public void _testPut() throws Exception { // put any stuff List<NodeData> nodes = prepare(); Set<Writer> writers = new HashSet<Writer>(); try { // create readers for (int t = 1; t <= 100; t++) { NodeData[] ns = new NodeData[nodes.size()]; nodes.toArray(ns); Writer r = new Writer(ns, "writer #" + t, 50); writers.add(r); r.start(); } Thread.sleep(5 * 60 * 1000); } finally { // join for (Writer w : writers) { w.cancel(); w.join(); } // debug result for (Writer w : writers) { log.info(w.getName() + " " + (w.itemsProcessed)); } } }
public int setData(Writer w, int data_) { int tmp; try { System.out.println( w.getName() + " has entered with data = " + data + ". Setting data to " + data_); tmp = data; data = data_; try { w.sleep(500); } catch (InterruptedException ex) { Logger.getLogger(Datastore.class.getName()).log(Level.SEVERE, null, ex); } return tmp; } finally { System.out.println(w.getName() + " has exited with data = " + data + "."); } }