• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Multithreading  RSS feed

 
Ran Luer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I have some question regarding multithreading in java
So I have developed a Java RMI program where client will send request to master server and master server will split task to several sub server. My program is now working as intended but i have some problem regarding multithreading (inside the sub server)

Supposely, sub server need to use thread (specified by client) to do the task given. Below is my code so far


After observing the time taken for each thread it seems that sometime time taken for 1 thread is shorter than 2 - 5 thread. And there are time when 1 is longer than 2 but is shorter than 3-5 (i hope you get what i mean) and rarely 5 is shorter than 1-4 thread.
I thought 5 thread will always take shorter time compare to 1-4 thread.
I am told that overhead is the causes of this problem. I would like to ask,

  1. Is there any solution to overhead? I mean is there any way to make sure that time taken for 5 thread is always shorter than 1-4 thread when using Java RMI?
  2. I have test this on non rmi program, and the result is 5 thread is always shorter than 1-4 thread. Does RMI really affect the performance of multithreading?

I am not expecting any code from any of you guys. I would like to have a clear view on this problem. I would appreciate any reliable sources (reading material) if any

Thank you>
 
Ran Luer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry for the code. I cant seems to find the edit code. So I'll just reply instead.


Sorry again for the mistake I made
 
Paul Clapham
Sheriff
Posts: 22813
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ran Luer wrote:I thought 5 thread will always take shorter time compare to 1-4 thread.


And would you expect 1000 threads to be faster than 1 thread? What about 1 million threads? No, by that point you might expect the overhead of keeping track of 1 million threads would be fairly large.

And are the 1 million threads all running at the same time? No, your computer doesn't have the hardware to do that. The threads have to take turns running. So using 1 million threads would be silly (which is what you already thought as soon as you read that).

What I'm trying to say here is that using multiple threads isn't as straightforward and simple as you might think. Using more threads isn't always better than fewer threads.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!