Advertisement
Guest User

Untitled

a guest
Sep 11th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ConcurentLinkedQueue<MyObject> queue;
  2.  
  3. ResultSet rs = /* SELECT href from LINKS */;
  4. while(rs.hasNext()) {
  5.   MyObject o = new MyObject(rs.next());
  6.   queue.add(o);
  7. }
  8.  
  9. /* create & start threads */
  10. for(int i = 0; i < 10; ++i) {
  11.   MyThread t = new MyThread(queue);
  12.   t.start();
  13. }
  14.  
  15. /* inside MyThread */
  16. void threadMethod() {
  17.   MyObject o = null;
  18.   while((o = queue.poll()) != null) {
  19.     /* process myobject */
  20.   }
  21.   System.out.println("no more items, thread shutting down.");
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement