private void runConcurrentStuff(final SailRepository repo,final int maxCounter) throws Exception, InterruptedException { try { final List<Callable<Void>> tasks = new LinkedList<Callable<Void>>(); tasks.add(new DoStuff(repo, true/*writer*/, maxCounter)); tasks.add(new DoStuff(repo, false/*reader*/, maxCounter)); tasks.add(new DoStuff(repo, false/*reader*/, maxCounter)); final List<Future<Void>> futures = executorService.invokeAll(tasks); // Look for the first cause. final Throwable t = firstCause.get(); if (t != null) { // Found it. throw new RuntimeException(t); } // test each future. for (Future<Void> f : futures) { f.get(); } } finally { repo.shutDown(); } }
private void runConcurrentStuff(final SailRepository repo,final int maxCounter) throws Exception, InterruptedException { try { final List<Callable<Void>> tasks = new LinkedList<Callable<Void>>(); tasks.add(new DoStuff(repo, true/*writer*/, maxCounter)); tasks.add(new DoStuff(repo, false/*reader*/, maxCounter)); tasks.add(new DoStuff(repo, false/*reader*/, maxCounter)); final List<Future<Void>> futures = executorService.invokeAll(tasks); // Look for the first cause. final Throwable t = firstCause.get(); if (t != null) { // Found it. throw new RuntimeException(t); } // test each future. for (Future<Void> f : futures) { f.get(); } } finally { repo.shutDown(); } }
private void writer(final RepositoryConnection conn) throws RepositoryException, MalformedQueryException, QueryEvaluationException, InterruptedException { final URI subj = conn.getValueFactory().createURI( "u:s" + (counter++)); final Value value = conn.getValueFactory().createLiteral( "literal" + counter); query(conn); // Thread.sleep(200); conn.add(subj, conn.getValueFactory().createURI("u:p"), subj); conn.add(subj, conn.getValueFactory().createURI("u:p"), value); conn.commit(); if(log.isInfoEnabled()) log.info("Added statements: size="+conn.size()); // if (counter % 12 == 0) { // conn.close(); // conn = repo.getConnection(); // conn.setAutoCommit(false); // } }
private void writer(final RepositoryConnection conn) throws RepositoryException, MalformedQueryException, QueryEvaluationException, InterruptedException { final URI subj = conn.getValueFactory().createURI( "u:s" + (counter++)); final Value value = conn.getValueFactory().createLiteral( "literal" + counter); query(conn); // Thread.sleep(200); conn.add(subj, conn.getValueFactory().createURI("u:p"), subj); conn.add(subj, conn.getValueFactory().createURI("u:p"), value); conn.commit(); if(log.isInfoEnabled()) log.info("Added statements: size="+conn.size()); // if (counter % 12 == 0) { // conn.close(); // conn = repo.getConnection(); // conn.setAutoCommit(false); // } }
private void reader(final RepositoryConnection conn) throws RepositoryException, MalformedQueryException, QueryEvaluationException, InterruptedException { query(conn); // Thread.sleep(100); query(conn); ++counter; if (counter % 3 == 0) conn.commit(); else conn.rollback(); // if (counter % 7 == 0) { // conn.close(); // conn = repo.getConnection(); // conn.setAutoCommit(false); // } }
private void reader(final RepositoryConnection conn) throws RepositoryException, MalformedQueryException, QueryEvaluationException, InterruptedException { query(conn); // Thread.sleep(100); query(conn); ++counter; if (counter % 3 == 0) conn.commit(); else conn.rollback(); // if (counter % 7 == 0) { // conn.close(); // conn = repo.getConnection(); // conn.setAutoCommit(false); // } }