multithreading - Java thread execution order when using Timer and TimerTask -


I am using a timer as a process, the flow of logic is as follows:

T0 : Create a new timer on T0 and schedule a new timer task to execute on T2 (1 second work delay, task is very easy - determines a flag variable)

T1: Main calling In the thread, sleep for 5 seconds

T2: In the timer thread, executed

T5: Sleeping

T6: TIMER or cancel any scheduled task

This code does my Windows and Ubuntu Dev works perfectly on the environment. But when I run the same code on my SLES 10 build server, logging indicates this execution order:

T0: Timers and timer work are created to execute on T2

T1: The main thread sleeps for 5 seconds

T5: the main thread awakens

T6: timer cancellation

T7: executed

Why is it interpreted as why? Thanks a lot.

Hm I wonder if you see a lot of difference (in seconds?), But I think that It is possible that you see different sequences of performance from machine to machine, jvm to jvm etc. Specifically, when JIT is compiling your code, for example, for the first time, I get to see the delay in order of 100-300 mms (compared to the execution of the same code) in my code, then it may be your Is the code more dramatic?

Not sure what you mean with "the process between the process" do you mean that the timer work interrupts some threads?

Anyway, the suggestion I can give is to use it instead of System.nanoTime () . (Although I do not think it will explain anything, using the System.currentTimeMillis () has been frustrated in a serious measure). Adding your JAVA_OPTS to - server It is generally advised that when the code is optimized by JIT, you see the behavior. It is highly advised to run your code multiple times and take data.

If I were you, then I will do these little things first, then debug it using synchronizers such as CyclicBarrier , countdown Where is the delay in the time.

What is "background noise" in SLES (activity degree)? Maybe the OS is too busy or something else?

What is the nature of the work? Is it related to some network / IO?


Comments