• Post Reply Bookmark Topic Watch Topic
  • New Topic

gettting arraylist values using multithreading  RSS feed

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have one arraylist its contains suppose 1000 objects.now the requirenment is have to get these
values using multithreading.for example i have 2 threads now i want that 1 thread should get 1-500 objects
and the next thread should get 501-1000 objects.
this question is asked by interviwer.
so just let me know the approch.
Thanks in advance
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eshwin Sukhdeve wrote:this question is asked by interviwer.

So what did you reply ?
 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that is what ..i couldn't give the reply..
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First create a class that can fetch objects from an ArrayList.
Then add the ability to tell that class to only access certain elements of an ArrayList.
Then add the ability to run that class in a separate thread.
Create two instances of that class, tell them the range of objects they have to access and run them in separate threads.

What parts of that can't you do ?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And of course you have to ask the interviewer if you can assume anything about whether the list might be updated while you're reading, as that will add an extra piece to your approach, and, depending on how you handle it, may negate the point of multithreading completely.

If I were the interviewer, I'd be as interested in how that discussion proceeds as in how you answer the original question.
 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Joanne Neal-you have mentioned that first create a class that fetch the objects from arraylist.at this point only i want to fetch the objects
from arraylist using mulithreading.means while fetching first half(arraylist) will taken by First thread and second half(arraylist) by second thread
in parallel.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eshwin Sukhdeve wrote:@Joanne Neal-you have mentioned that first create a class that fetch the objects from arraylist.at this point only i want to fetch the objects
from arraylist using mulithreading.means while fetching first half(arraylist) will taken by First thread and second half(arraylist) by second thread
in parallel.

I was showing you a step by step approach to the problem. Don't try and do the whole thing at once.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eshwin Sukhdeve wrote:@Joanne Neal-you have mentioned that first create a class that fetch the objects from arraylist.at this point only i want to fetch the objects
from arraylist using mulithreading.means while fetching first half(arraylist) will taken by First thread and second half(arraylist) by second thread
in parallel.


How are you planning to do that without a class?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!