Do each java program requires each jvm to run? [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Consider, I have a simple java program to add 2 numbers. If I run this program in 2 different terminals, in how many JVMs do they run?

Each one has its own JVM instance. That should be obvious to you because the java command is not a system service.

Yes it does, unless you run multiple programs together and use a wrapper that starts each program in a different thread, as you can have multiple threads running within one JVM.

Related

Java: how to execute easily a program in an other computer? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to execute the program I've written in Java in another computer different from mine. Is there a way to make it run without having to set the system and enviroment variables and without having to compile it manually through the shell? It would be great if I could just click on a file and make it run. Thank you
Create a runnable jar. If the user has his Java set up properly, it can be run by double clicking on the jar.
(Provided of course that you don't make it depend on paths or other things on your particular computer).

How to make auto log out when idle? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I made a java swing application. Now I want to make it auto log out when user is idle.
Is there any way to detect 'idle' in java swing? I have no idea how to do it.
Check out Application Inactivity for one approach.
in swing you can use System.exit(0); to kill your window in any case. In your case I am guessing that you want to logout after a definite time delay then for that you can use thread with your code.

Opening 2 audio-files and playing them simultaneously [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
Can I play 2 sound-files simultaneously?
I can handle the loading, changing loudness, opening and closing of one file.
How can I load 2 files in separate frames and start the playing with simultaneously hearing.
Put the opening and the playing into two separate threads, then start them. The two threads can be synchronized so the playback starts synchronously.

How to compile a program (with gcc)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am writing a cross-platform IDE, and am wondering what the best way to compile a program (with gcc) using java code. (It's also a cross-language IDE)
Should I access the command prompt/terminal?
Also can I have some example code?
You can probably just execute gcc in a separate process. But rather than handling this all yourself, use something like Apache Commons Exec, which is great for this sort of thing.

What is the mechanism to ensure that 2 different process should not read\write to the same file at a time in java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I m working in java. I have an application which will read & write one sample.txt file.
And one more application which will also read & write to same file.
And first application will run for every 1 minute as windows service.
My doubt is now how, can make sure that both applications should r/w at the same time.
Any suggestions plz.
As you want to lock access from different application if i understand it right. You can use FileLock here an example
You need to guard the file access code through synchronized block or methods. Learn more about synchronization here:
http://javarevisited.blogspot.in/2011/04/synchronization-in-java-synchronized.html
Simples solution is to use the synchronized keyword.
public synchronized int i = 1;
in this way i can only be accessed from one thread at the time. But this is expansive! There are many concepts of synchronization, e.g. the monitor
Read this for more information: http://www.artima.com/insidejvm/ed2/threadsynch.html

Categories

Resources