@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { try { // waiting for a thread to pick up instead of throwing exceptions. queue.put(r); } catch (InterruptedException e) { throw new RejectedExecutionException(e); } } });
void monitor(MonitorTask task) throws InterruptedException { boolean isAlive = false; synchronized (this) { if (this.alive) { isAlive = true; this.producer = Thread.currentThread(); } } if (isAlive) { try { this.task.put(task); } catch (InterruptedException e) { // fall through and return } finally { synchronized (this) { this.producer = null; } } } }
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { try { // waiting for a thread to pick up instead of throwing exceptions. queue.put(r); } catch (InterruptedException e) { throw new RejectedExecutionException(e); } } });
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { try { // waiting for a thread to pick up instead of throwing exceptions. queue.put(r); } catch (InterruptedException e) { throw new RejectedExecutionException(e); } } });
public void handle(String data) { try { String value = getBeakerArgValue(data); this.beakerXClient.getMessageQueue(URL_ARG).put((value == null) ? "" : value); } catch (InterruptedException e) { throw new RuntimeException(e); } }
public void handle(String data) { try { List<CodeCell> cells = getBeakerCodeCells(data); BeakerXClientManager.get().getMessageQueue("CodeCells").put(cells); } catch (InterruptedException e) { e.printStackTrace(); } }
@Override public OAuthTokenFinish call() throws Exception { logger.log(Level.INFO, "Waiting for token response"); final String urlWithIdAndToken = (String) ioQueue.take(); logger.log(Level.INFO, "Parsing token response " + urlWithIdAndToken); OAuthTokenFinish tokenResponse = null; // null if parsing failed (user canceled, api error, ... try { tokenResponse = extractor.parse(urlWithIdAndToken); ioQueue.put(OAuthWebResponses.createValidResponse()); } catch (NoSuchFieldException e) { logger.log(Level.SEVERE, "Unable to find token in response", e); ioQueue.put(OAuthWebResponses.createBadResponse()); } ioQueue.take(); // make sure undertow has send a response stop(); logger.log(Level.INFO, tokenResponse != null ? "Returning token" : "No token received, returning null"); return tokenResponse; }
/** * Process task. * * @param task the task to be processed * @throws InterruptedException when thread has been interrupted */ public void process(WebcamTask task) throws InterruptedException { inbound.put(task); Throwable t = outbound.take().getThrowable(); if (t != null) { throw new WebcamException("Cannot execute task", t); } }
@Override public void run() { assertSame(this, Thread.currentThread()); try { while (true) { Request request = requestQueue.take(); Object result; try { result = invokeMethod(request.methodName, request.arguments); } catch (ThreadDeath death) { return; } catch (InvocationTargetException exception) { responseQueue.put(new Response(request.methodName, null, exception.getTargetException())); continue; } catch (Throwable throwable) { responseQueue.put(new Response(request.methodName, null, throwable)); continue; } responseQueue.put(new Response(request.methodName, result, null)); } } catch (ThreadDeath death) { return; } catch (InterruptedException ignored) { // SynchronousQueue sometimes throws InterruptedException while the threads are stopping. } catch (Throwable uncaught) { this.uncaughtThrowable = uncaught; } }
@Override public void run() { while (true) { WebcamTask t = null; try { (t = inbound.take()).handle(); } catch (InterruptedException e) { break; } catch (Throwable e) { if (t != null) { t.setThrowable(e); } } finally { if (t != null) { try { outbound.put(t); } catch (InterruptedException e) { break; } catch (Exception e) { throw new RuntimeException("Cannot put task into outbound queue", e); } } } } } }
slopQueue.put(END); } catch(InterruptedException e) { logger.warn("Error putting poison pill", e);
@Override public Long call() throws Exception { ExcerptTailer tailer = queue.createTailer(); tailer.moveToIndex(startIndex); Long fromWriter = sync.take(); long index = doReadBad(tailer, messages + 50, false); if (index != fromWriter) { System.out.println("Reader:1 Not the same:" + index + " vs. " + fromWriter); } sync.put(index); fromWriter = sync.take(); index = doReadBad(tailer, 50, false); if (index != fromWriter) { System.out.println("Reader:2 Not the same:" + index + " vs. " + fromWriter); } return index; } }
writtenRows.add(value); rowQueue.put(new KeyValue<>(key, value));
public static void notifySynchronousQueue(String spiUUID, SPI spi) throws InterruptedException { SynchronousQueue<SPI> synchronousQueue = _synchronousQueues.remove( spiUUID); if (synchronousQueue == null) { throw new IllegalStateException( "No SPI synchronous queue with uuid " + spiUUID); } synchronousQueue.put(spi); }
@Override public void run() { try { CoordinateReferenceSystem crs = doShow(title, initialCode, authority); if (crs == null) { currentThread.interrupt(); } else { sq.put(crs); } } catch (InterruptedException ex) { throw new RuntimeException(ex); } } });
@Override public Long call() throws Exception { queue = ChronicleQueue.singleBuilder(path) //.testBlockSize() //.rollCycle(TEST_DAILY) .buffered(false) .build(); appender = queue.acquireAppender(); for (int i = 0; i < 50; i++) { appender.writeDocument(wireOut -> wireOut.write("log").marshallable(m -> m.write("msg").text("hello world2 "))); } long index = appender.lastIndexAppended(); sync.put(index); Long fromReader = sync.take(); if (index != fromReader) { System.out.println("Writer:Not the same:" + index + " vs. " + fromReader); } for (int i = 0; i < 50; i++) { appender.writeDocument(wireOut -> wireOut.write("log").marshallable(m -> m.write("msg").text("hello world2 "))); } index = appender.lastIndexAppended(); sync.put(index); return index; } }
run(() -> { for (int i = 0; i < LIMIT; i++) { synchronousQueue.put(O); limit.getPermission(TIMEOUT);
@Override public void run() { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.option(ChannelOption.SO_BACKLOG, 1024); bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .childHandler(new ServerInitializer(handlers)); Channel ch = bootstrap.bind(port).sync().channel(); // Should always be an InetSockedAddress, because we call bind() if (!(ch.localAddress() instanceof InetSocketAddress)) { throw new RuntimeException("Expected an InetSocketAddress"); } int startedPort = ((InetSocketAddress) ch.localAddress()).getPort(); queue.put(startedPort); ch.closeFuture().sync(); } catch (InterruptedException ignored) { } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); TrafficCounter.shutdown(); } } };
public ConcurrentSender send(final TaggedLogAPIEntity entity) throws InterruptedException { if(!this.isStarted){ this.start(); } this.queue.put(entity); return this; }
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { try { // waiting for a thread to pick up instead of throwing exceptions. queue.put(r); } catch (InterruptedException e) { throw new RejectedExecutionException(e); } } });