• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running two threads

 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21190
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or a variable "r"
 
Henry Wong
author
Marshal
Pie
Posts: 21190
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a sample code of the issue I'm having:



Thanks in advance for everyone's help.
 
Henry Wong
author
Marshal
Pie
Posts: 21190
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic