Reputation: 677
I want to achieve something like this :
continually check if a process was started every "x time unit"
when the process was found to be ON "start task Y"
Because this application will run for long periods of time due to its nature, I'm worried about memory consumption (task Y is quite large).
Is it better to use:
or
With the second solution I don't have to load all my application in memory all this time, only when the check returns true. Does it work the same with multithreading?
Thanks!
Upvotes: 0
Views: 46
Reputation: 103797
Broadly speaking, it's not going to make much difference. Regardless of which approach you take, you're going to need enough memory on the box to handle task X and task Y running simultaneously.
If anything, a multithreaded (single-app) approach might have a slightly lower memory footprint, as it would not require loading two copies of the common elements (e.g. the JDK and standard library itself). But I doubt there would be much in it in practice.
Writing a multithreaded application is likely to be simpler, as well. There's less to go wrong when you're just submitting task Y to an executor, compared to trying to send a message to a different process. (What happens if the other process isn't running? What happens if you're dropping trigger files and the disk is full, or you're communicating by ports and get an IOException, or...)
Upvotes: 1