This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Handling

 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am new to this discussion group. I found that there are many good discussion about SCJD exam. It helps me a lot in term of doing the design.
However, I did not see any discussion about multi-thread handling. How should we handle the multi-threading for the exam ? Should we create a thread pool in server side ? Where can I find the best reference about creating thread pool ? I found several books talk about it, all of them looks very complicated.
 
Matt Ghiold
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you choose RMI for a solution, this is all handled for you. Natively RMI has a thread pool, socket reuse and is multi-threaded. Hope this helps.
If you choose sockets, you will have to right your own.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use sockets, remember the "favour clarity over performance" requirement and don't use a thread pool. IMHO you'd simply create threads as required.
- Peter
 
Pete Harris
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seem to be the only person using serialization here and I agree with Peter - Don't use a thread pool. The simple answer is to have one thread per connected clientas this endures that there are no thread management issues.
 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going to use RMI. I have already written a thread pool by following a book. It is nice to know that RMI has already handle the thread pool for me. I will remove the code that I wrote. (It has already be tested without using RMI). Thanks.
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,
It's important to know that, even using RMI, you can still run into threading issues. A Thread pool make sure that you're not wasting threads, but it doesn't keep two threads from attempting to modify the same resource. That's where your locking code comes in.
HTH,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic