0

Hie, I am looking a way to store suspended the Thread and resume it after the restart of JVM.

Any leads will be greatly appreciable.

It's not necessary that thread name, Thread group should be the same after the restart. On Thing which is to be considered is Resumed should follow the same follow if we resume it before JVM restart. All variable should be stored which thread handles or access it.

Akhil Surapuram
  • 654
  • 1
  • 8
  • 22
  • Related : https://stackoverflow.com/questions/424341/are-there-any-java-vms-which-can-save-their-state-to-a-file-and-then-reload-that – Brian Agnew Aug 13 '18 at 09:09
  • Assume That thread is performing batch operations like the processing on the scalable number of records usually takes some hours to process it. – Akhil Surapuram Aug 13 '18 at 10:01
  • Why do you need to do this? What you're actually asking for is close to impossible, but if you explain your ultimate goal then there may be a different solution. – davmac Aug 13 '18 at 11:39
  • @davmac can you pls explain me in detail what makes you think this close to impossible. – Akhil Surapuram Aug 14 '18 at 06:37
  • @AkhilSurapuram it's close to impossible because there's no way to do it. If the JVM restarts it loses its state, the thread that once existed does not exist anymore, you cannot therefore resume it. – davmac Aug 14 '18 at 08:54

1 Answers1

1

There is no way to do that. Forget any thoughts of persisting threads. It is not achievable with any known production-quality JVM.

You are better of simply storing the queue of tasks to be done in a transactional database (or a message queuing system) and writing the task code to be restartable. If an individual task takes long enough that restarting a task is not acceptable ... split the task into smaller tasks, or implement task checkpointing.

(What you would really like is a JVM that implements orthogonal persistence AND has the ability to persist threads AND the ability to persist database connections with active queries. As far as I am aware NONE of these things is available in any JVM implementation, let alone all of them.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216