Sunday, 15 May 2011

java - Save and restart the thread pool after server shutdown -



java - Save and restart the thread pool after server shutdown -

my application have multiple threads. in case server goes downwards or restarted, want execute threads not executed. illustration in snippet below: consider if server goes downwards after thread number 1,4,2 executed. applicaiton should execute 2,3 , 5 threads after server restarts.

the task of threads atomic in nature. either of gets done or nil happens. have somehow save sate of every thread executed. how can that?

class hugejob implements runnable { int param; public hugejob(int var) { this.param = var; } public void run() { //this atomic task i.e. either gets done or nil //each thread task takes ~20 minute. heavy i/o , network operations //i have create sure no thread executes more 1 time if server restarted system.out.println(this.param); } } public class threadsample { public static void main(string [] args) { for(int =0; i<5;i++) { hugejob obj = new hugejob(i); new thread(obj).start(); } } }

thanks help.

edit can utilize quartz accomplish this? thought create each , every thread s separate job , persist using quartz? here related link: javaquartz job persistence

i believe requirements impossible variant of byzantine generals problem, provably unsolvable. thread beingness done analogous 1 of generals attacking recording needed ensure thread not run 1 time again analogous other general attacking. requirement analogous requirement either both generals attack or neither impossible meet.

you cannot avoid next basic problem.

the thread finishes.

you record thread finished such don't work again.

what if scheme shuts downwards after 1 before 2?

you need rethink problem , requirements. oversimplified version you've presented cannot solved asked.

java multithreading threadpool runnable threadpoolexecutor

No comments:

Post a Comment