File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Running two threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Running two threads" Watch "Running two threads" New topic
Author

Running two threads

Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
Hello.
I am trying to learn how to multithread. So I have taken sample code from the Java Thread Programming book and modified it so that I can run two instances. When I run the following code I get two application instances however when I close one of the windows both of them close. By exiting one of the applications the other should continue to run?

Please let me know where I have made an error.

Thank you for your help.
Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
Unfortunately, I was unable to add my code due to the "international abbreviation" error message. If someone would please let me know how I can, I will post another message with the code. I tried using the "Instant UBB Code" tags.

Thank you.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

By international abbreviation error, do you mean the recently added check to prevent instant messenger shortcuts? This was added to promote more clarity in the posts -- as non-english speakers are having a difficult time understanding some of them.

Unfortunately, there is no easy tag to fix it at the moment. However, it is easy to fix externally -- the error will inform you of the invalid word that you are using.

Basically, you'll need to change your code to not use the abbreviations for "please" (P-L-Z), "great" (G-R-8), "thanks" (T-H-X), etc. If you are using an IDE, it should be a simple refactor operation.

Sorry for the inconvenience,
Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Or a variable "r"


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

FYI... There is a discussion in the JavaRanch forum related to this very issue. In that case, I believe it was caused by the variable "u". Anyway, if anyone would like to voice an opinion about this, along with any constructive suggestions, you may find the thread here.

Henry
Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
Here's a sample code of the issue I'm having:



Thanks in advance for everyone's help.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

Take a look at your windowclosing event handler. It calls System.exit(). This basically causes the JVM to exit. The whole program exits -- regardless of how many windows it created.

Henry
Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
Henry,
Thank you for your hint. I'm glad you gave me a hint instead of the answer. I can retain information longer if I figure it out on my own. =)

Here's how I fixed it:


Thank you again!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running two threads
 
Similar Threads
null instance variable after assigning a value
question on JSP directive
Tomcat Cluster / Load Balancing
How to set a different port number to for Tomcat 6
Example for java doubleton pattern.