• 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

Fixed Thread Pools

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I started a thread on this forum last week about dealing with client/server connections and starting a new thread
each time a client connected. Jayesh A Lalwani helped me in solving the issue and then gave me some suggestions
about how I could improve the design, which I greatly appreciated.

After doing some research on thread pools I tried to implement them into my program and succeeded...partially. I
have a few questions regarding the appropriate use of thread pools and was hoping someone more experienced here
could help me understand them a little better.

Firstly, my RejectedExecutionException handler is not catching the error whenever I try to connect an additional
client...instead the second client will simply hang.

Secondly, if I connect two clients, the first one will connect and function correctly. The second one will accept
and send text but will not receive anything since it is waiting in the que...however if I send a message with the
second client while it is waiting then proceed to send a message with the first client suddenly both clients will
receive the messages and start functioning correctly. How can this happen?

Thirdly, how can I stop an individual thread that exists within an executor while leaving the other threads alone?

I appreciate your time and help!



 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For your second problem, I think you need to call flush() in your output streams after writing.

For your third problem, threads should be stopped using interrupts. You should use submit() instead of execute() which returns a Future instance. And then you can call cancel() on that instance which will interrupt the thread.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you put some more logs in your Runnable and post what you see?. Also, are both of your clients getting the "succesfuly connected..." message?

Why do you want to stop individual threads? You shouldn't be stoppign threads. You should let the executor manage it's own threads.
 
Their achilles heel is the noogie! Give them noogies tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic