0

I'm currently working with an application that does some heavy computational work. It has been ported from C to Java years ago and it shows a bit. Among others it uses public static variables to share data between classes.

The work is very suited for parallelizing as multiple files are processed and every file can be done completely independ of others. But just starting multiple threads doesn't work because of the static variables. I would like to prevent a rewrite because the classes are quite fast, mature and bug-free.

Is there an easy way for me to start multiple threads/processes from within the java program wherein each thread will have it's own copy of the static variables or will I have to resort to just calling the JVM multiple times by executing commands?

1
  • I don't think there is any "Application Domains" support for the standard JVM .. but there may be some nifty trickery or approaches with different classloaders? If you cannot change the code (and it's a "known working" approach), I would use separate processes to increase the isolation - assuming that said processes are concurrency-capable. Commented Sep 26, 2013 at 19:31

1 Answer 1

3

Yes, You can use multiple class loaders, or start multiple processes.

However, I suggest just fixing the code, it would be much simpler. Make all the static fields, non static and have a ThreadLocal variable which hold the instance copy for that thread.

Sign up to request clarification or add additional context in comments.

1 Comment

I would say that calling java.exe Class arguments a few times (and thus starting multiple processes) is a lot simpler than altering 5K LOC of complicated code, especially if the code otherwise is bug-free an performs well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.