Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

2 threads, one for array input and other for sum of elements in the array  RSS feed

 
Abhimanyu Jain
Ranch Hand
Posts: 151
1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have two threads, one for an int array input and other for calculating the sum of the elements in the array. I am able to create the first thread which takes an int array but not the second one. Please help

The code is as follows:

 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem in hand is - you want to transfer information from one thread to another thread

If you want to transfer each number [ array element] of array individually then you can trying using Blocking Queue where your one thread places the array element on blocking queue .. then .. another thread takes that number from blocking queue and perform the summation. Hint - try to apply Producer Consumer thread pattern here [ using wait/notify or blocking queue] . Producer is the thread read number from console. Consumer thread is the thread doing summation.

If you want to transfer whole array at one go from one thread to another thread, probably you do not require any threads. Steps can be done sequentially.


 
Abhimanyu Jain
Ranch Hand
Posts: 151
1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!

I will give that a try and check.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!