• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 151
1
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you!

I will give that a try and check.

 
reply
    Bookmark Topic Watch Topic
  • New Topic