• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Running two threads

 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or a variable "r"
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic