简体   繁体   中英

Run two java files concurrently

I have two java applications. They are very simple: they insert 500,000 rows of fake data into a MongoDB database and SQL database respectively. I time each operation.

How can I launch these two java files at the exact same time?

How exact does exact mean? Running them at exactly the same time is going to be damn near impossible, and fully impossible on a single-core machine (not that those still exist...).

But the easiest thing, if you want them launched very quickly, is:

java -jar first.jar & java -jar second.jar

If there's some startup time that you want to synchronize after, you could rig them both such that they busy-wait for a signal from an external event (such as a file appearing). Then start them both up, wait for them to warm up, and trigger the signal.

There is no need to start them at the same time (and you can't be 100% exact). You just have to measure how much time each one executes.

If this doesn't suit you, perhaps you can setup 2 crons to start the two applications.

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