简体   繁体   中英

Running two classes inside jar

I have created a runnable jar with two main classes. One is simple class file and other is having thread. I can able to execute both the classes. But my question is if we executed the thread class and it starts running. Now we start the execute the normal class often. Does this cause over memory usage.

Starting both classes separately, starts 2 JVM process for running the code. Each execution is totally separated and your class 1 can not interact (easily) with your class 2 started in another JVM. You can also start or stop each process regardless of the other. But having 2 JVM running has a cost (especially on memory usage)

But it can be correct, depending on what you want to do.

Otherwise, you can have only one main method which starts both classes in same execution. Doing that will use only one JVM and processes can be easily communicate, just by calling methods on object instances.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM