Showing posts with label Thread. Show all posts
Showing posts with label Thread. Show all posts

Thursday, November 27, 2014

Changing the Eclipse Java thread time out value


Did you ever face below kind of issue while starting your eclipse product ? 

!ENTRY org.eclipse.osgi 2 0 2014-11-28 11:17:57.835
!MESSAGE While loading class "com.kk.tool.model.KContainer", thread "Thread[main,6,main]" timed out waiting (5015ms) for thread "Thread[Thread-3,5,main]" to finish starting bundle "com.kk.tool_6.0.190.DEV_v201411271801 [664]". To avoid deadlock, thread "Thread[main,6,main]" is proceeding but "com.kk.tool.model.KContainer" may not be fully initialized.
!STACK 0
org.osgi.framework.BundleException: State change in progress for bundle "reference:file:dropins/com.kk.tool_6.0.190.DEV_v201411271801.jar" by thread "Thread-3


There are two majors reasons for this.
1. Real dead lock would have occurred
2. Your product might have lot of bundles and each one of them might have dependencies on other plugins startup. Because of this, eclipse startup will be delayed.

If it is (1), we need to identify the root cause for a dead lock and fix it.

In general, OSGI controlling java threads time out by 5000 ms by default. We can control this time out by osgi parameter which need to be configured in the config.ini file.

equinox.statechange.timeout=8000

You can find config.ini file in the configuration folder of eclipse directory.
<eclipse>/configuration/config.ini

Caution: Don't jump strait to the timeout solution with out really looking at the dead lock possibility, 99% of time problem might be there with our code only!!!!

Resources:



Thursday, May 9, 2013

Setting stack size to a Java thread

 From JavaDoc


java.lang.Thread.Thread(ThreadGroup group, Runnable target, String name, long stackSize)

Allocates a new Thread object so that it has target as its run object, has the specified name as its name, belongs to the thread group referred to by group, and has the specified stack size.
This constructor is identical to Thread(ThreadGroup, Runnable, String) with the exception of the fact that it allows the thread stack size to be specified. The stack size is the approximate number of bytes of address space that the virtual machine is to allocate for this thread's stack.

The effect of the stackSize parameter, if any, is highly platform dependent.
On some platforms, specifying a higher value for the stackSize parameter may allow a thread to achieve greater recursion depth before throwing a StackOverflowError. Similarly, specifying a lower value may allow a greater number of threads to exist concurrently without throwing an OutOfMemoryError (or other internal error). The details of the relationship between the value of the stackSize parameter and the maximum recursion depth and concurrency level are platform-dependent. On some platforms, the value of the stackSize parameter may have no effect whatsoever.
The virtual machine is free to treat the stackSize parameter as a suggestion. If the specified value is unreasonably low for the platform, the virtual machine may instead use some platform-specific minimum value; if the specified value is unreasonably high, the virtual machine may instead use some platform-specific maximum. Likewise, the virtual machine is free to round the specified value up or down as it sees fit (or to ignore it completely).

Specifying a value of zero for the stackSize parameter will cause this constructor to behave exactly like the Thread(ThreadGroup, Runnable, String) constructor.

Due to the platform-dependent nature of the behavior of this constructor, extreme care should be exercised in its use. The thread stack size necessary to perform a given computation will likely vary from one JRE implementation to another. In light of this variation, careful tuning of the stack size parameter may be required, and the tuning may need to be repeated for each JRE implementation on which an application is to run.
Implementation note: Java platform implementers are encouraged to document their implementation's behavior with respect to the stackSize parameter.
Parameters:
group the thread group.
target the object whose run method is called.
name the name of the new thread.
stackSize the desired stack size for the new thread, or zero to indicate that this parameter is to be ignored.
Throws:
SecurityException - if the current thread cannot create a thread in the specified thread group.
Since:
1.4