public void setSync(Sync sync) { this.sync = sync; if (sync != Sync.SYNC) { if (tasks == null) { tasks = new PipeliningTaskQueue<Thread>(); tasks.start(); } } else { if (tasks != null) { dispose(); } } }
@Override protected void tearDown() throws Exception { taskQueue.stop(); }
public Object doInHibernate(Session session) throws HibernateException, SQLException { try { Transaction tx = session.beginTransaction(); // mergeLayers(data, session); session.update(data); tx.commit(); } catch (HibernateException e) { if (tasks != null) tasks.print(); throw e; } return null; } });
protected void run(Task task) { if (tasks != null) { tasks.execute(Thread.currentThread(), new Async(task), task.desc); } else { task.run(); } }
public void dispose() { if (tasks != null) { tasks.shutdown(); tasks = null; } }
for (int j = 0; j < workers.length; j++) { Worker w = workers[j].get(i); taskQueue.execute(w.group, w);
@Override protected void setUp() throws Exception { taskQueue = new PipeliningTaskQueue(); taskQueue.start(); }
@Test public void test() throws Exception { ConcurrentLinkedQueue<Worker> completed = new ConcurrentLinkedQueue<Worker>(); int groups = 5; ArrayList<Worker>[] workers = new ArrayList[groups]; for (int i = 0; i < workers.length; i++) { workers[i] = new ArrayList(); for (int j = 0; j < groups; j++) { workers[i].add(new Worker(i, j, completed)); } } for (int i = 0; i < groups; i++) { for (int j = 0; j < workers.length; j++) { Worker w = workers[j].get(i); taskQueue.execute(w.group, w); } } while (completed.size() < groups * workers.length) { Thread.sleep(1000); } int[] status = new int[groups]; for (Worker w : completed) { assertEquals(status[w.group], w.seq.intValue()); status[w.group]++; } }
@After public void tearDown() throws Exception { taskQueue.stop(); }
@Before public void setUp() throws Exception { taskQueue = new PipeliningTaskQueue(); taskQueue.start(); }