List of usage examples for java.lang Thread interrupted
public static boolean interrupted()
From source file:com.laxser.blitz.web.instruction.InstructionExecutorImpl.java
/** * @param inv/*from w w w .ja va 2 s.c o m*/ * @param instruction * @return * @throws StackOverflowError */ private Instruction translatesToInstructionObject(InvocationBean inv, Object instruction) throws StackOverflowError { int count = 0; while (!(instruction instanceof Instruction)) { if (count++ > 50) { throw new StackOverflowError("Unable to parse the instruction to an" + " Instruction object less than " + count + " times. Is the instruction" + " that returned by your controller" + " action is right?"); } if (Thread.interrupted() || instruction == null) { return null; } else { if (instruction.getClass() != String.class && !ClassUtils.isPrimitiveOrWrapper(instruction.getClass()) && instruction.getClass().getComponentType() == null && instruction.getClass().getAnnotation(Component.class) != null) { SpringUtils.autowire(instruction, inv.getApplicationContext()); } instruction = parseInstruction(inv, instruction); } } return (Instruction) instruction; }
From source file:com.cyberway.issue.extractor.RegexpHTMLLinkExtractor.java
protected boolean findNextLink() { if (tags == null) { tags = TextUtils.getMatcher(RELEVANT_TAG_EXTRACTOR, sourceContent); }/*from w w w. j a v a 2s . com*/ while (tags.find()) { if (Thread.interrupted()) { // TODO: throw an exception, perhaps, rather than just clear & break? break; } if (tags.start(8) > 0) { // comment match // for now do nothing } else if (tags.start(7) > 0) { // <meta> match int start = tags.start(5); int end = tags.end(5); processMeta(sourceContent.subSequence(start, end)); } else if (tags.start(5) > 0) { // generic <whatever> match int start5 = tags.start(5); int end5 = tags.end(5); int start6 = tags.start(6); int end6 = tags.end(6); processGeneralTag(sourceContent.subSequence(start6, end6), sourceContent.subSequence(start5, end5)); } else if (tags.start(1) > 0) { // <script> match int start = tags.start(1); int end = tags.end(1); processScript(sourceContent.subSequence(start, end), tags.end(2) - start); } else if (tags.start(3) > 0) { // <style... match int start = tags.start(3); int end = tags.end(3); processStyle(sourceContent.subSequence(start, end), tags.end(4) - start); } if (!next.isEmpty()) { // at least one link found return true; } } // no relevant tags found return false; }
From source file:org.pepstock.jem.node.https.Worker.java
@Override public void run() { // creates a custom context HttpContext context = new BasicHttpContext(null); // adds the IP address of the client // necessary when the job ends and client is waiting the end of the job context.setAttribute(SubmitHandler.JOB_SUBMIT_IP_ADDRESS_KEY, clientAddress.getHostAddress()); try {/*from w w w . j a v a 2 s.co m*/ // till connection is open while (!Thread.interrupted() && httpConnection.isOpen()) { // starts the HTTP request httpService.handleRequest(httpConnection, context); } } catch (ConnectionClosedException ex) { // client close the connection LogAppl.getInstance().ignore(ex.getMessage(), ex); LogAppl.getInstance().emit(NodeMessage.JEMC023E, "Client closed connection (" + clientAddress.getHostAddress() + ")"); } catch (IOException ex) { // any I/O error LogAppl.getInstance().ignore(ex.getMessage(), ex); LogAppl.getInstance().emit(NodeMessage.JEMC023E, "I/O error (" + clientAddress.getHostAddress() + ")"); } catch (HttpException ex) { // Protocol exception LogAppl.getInstance().ignore(ex.getMessage(), ex); LogAppl.getInstance().emit(NodeMessage.JEMC023E, "Unrecoverable HTTP protocol violation (" + clientAddress.getHostAddress() + ")"); } finally { // ALWAYS close connection try { httpConnection.shutdown(); } catch (IOException e) { LogAppl.getInstance().ignore(e.getMessage(), e); } } }
From source file:net.sf.maltcms.chromaui.charts.overlay.Peak1DOverlayChildFactory.java
/** * * @param list// w w w. j ava 2 s . c o m * @return */ @Override protected boolean createKeys(List<IPeakAnnotationDescriptor> list) { for (IPeakAnnotationDescriptor pad : peakOverlay.getActiveSelection()) { if (Thread.interrupted()) { return true; } list.add(pad); } return true; }
From source file:org.geowebcache.seed.JobMonitorTask.java
/** * Infrequently wake up and go through the list of running tasks to update the jobs (task groups). * @see org.geowebcache.seed.GWCTask#doActionInternal() *///from ww w . j a v a 2 s . c o m @Override protected void doActionInternal() throws GeoWebCacheException, InterruptedException { super.state = GWCTask.STATE.RUNNING; Thread.currentThread().setPriority(PRIORITY.LOW.getThreadPriority()); int consecutiveFailures = 0; initCron4J(); scheduleOldJobPurgeTask(); restartInterruptedTasks(); while ((!Thread.interrupted()) && super.state != GWCTask.STATE.INTERRUPTED) { try { Iterator<Entry<Long, GWCTask>> tasks = seeder.getRunningTasksIterator(); List<Long> jobIds = new ArrayList<Long>(); while (tasks.hasNext()) { GWCTask task = tasks.next().getValue(); if (!(task instanceof JobMonitorTask)) { if (!jobIds.contains(task.getJobId())) { jobIds.add(task.getJobId()); JobObject job = new JobObject(); job.setJobId(task.getJobId()); if (jobStore.get(job)) { job.update(seeder); jobStore.put(job); } } } } // clear out completed tasks jobIds = new ArrayList<Long>(); while (!finishedTasks.isEmpty()) { GWCTask task; synchronized (finishedTasks) { task = finishedTasks.poll(); } if (!(task instanceof JobMonitorTask)) { if (!jobIds.contains(task.getJobId())) { jobIds.add(task.getJobId()); JobObject job = new JobObject(); job.setJobId(task.getJobId()); if (jobStore.get(job)) { job.update(task); jobStore.put(job); } } } } consecutiveFailures = 0; } catch (Exception e) { log.error("During job monitor task: " + e.getClass().getName() + ": " + e.getMessage()); consecutiveFailures++; if (consecutiveFailures > 5) { log.error("5 consecutive failures in a row, job monitoring will be shut down."); super.state = GWCTask.STATE.DEAD; } } Thread.sleep(updateFrequency); } if (super.state != GWCTask.STATE.DEAD) { super.state = GWCTask.STATE.DONE; log.debug("Completed job monitoring."); } }
From source file:org.apache.axis2.transport.http.server.DefaultConnectionListener.java
public void run() { try {/*from ww w .j a v a 2 s . com*/ while (!Thread.interrupted()) { try { if (serversocket == null || serversocket.isClosed()) { if (LOG.isInfoEnabled()) { LOG.info("Listening on port " + port); } serversocket = new ServerSocket(port); serversocket.setReuseAddress(true); } LOG.debug("Waiting for incoming HTTP connection"); Socket socket = this.serversocket.accept(); if (LOG.isDebugEnabled()) { LOG.debug("Incoming HTTP connection from " + socket.getRemoteSocketAddress()); } AxisHttpConnection conn = new AxisHttpConnectionImpl(socket, this.params); try { this.connmanager.process(conn); } catch (RejectedExecutionException e) { conn.sendResponse(new DefaultHttpResponseFactory().newHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_SERVICE_UNAVAILABLE, new BasicHttpContext(null))); } } catch (java.io.InterruptedIOException ie) { break; } catch (Throwable ex) { if (Thread.interrupted()) { break; } if (!failureHandler.failed(this, ex)) { break; } } } } finally { destroy(); } }
From source file:io.s4.example.twittertopiccount.TwitterFeedListener.java
public void run() { long backoffTime = 1000; while (!Thread.interrupted()) { try {//from ww w . j av a2 s . c o m connectAndRead(); } catch (Exception e) { Logger.getLogger("s4").error("Exception reading feed", e); try { Thread.sleep(backoffTime); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } backoffTime = backoffTime * 2; if (backoffTime > maxBackoffTime) { backoffTime = maxBackoffTime; } } } }
From source file:com.replaymod.replaystudio.launcher.DaemonLauncher.java
public void launch(CommandLine cmd) throws Exception { int threads = Integer.parseInt(cmd.getOptionValue('d', "" + Runtime.getRuntime().availableProcessors())); worker = Executors.newFixedThreadPool(threads); System.setOut(new PrintStream(systemOut = new ThreadLocalOutputStream(System.out))); ServerSocket serverSocket = new ServerSocket(PORT); System.out.println("Daemon started on port " + PORT + " with " + threads + " worker threads."); while (!Thread.interrupted()) { Socket socket = serverSocket.accept(); try {//from w w w . j a v a 2 s . c o m Client client = new Client(socket); new Thread(client).start(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.apache.axis2.transport.http.server.HttpServiceProcessor.java
public void run() { LOG.debug("New connection thread"); HttpContext context = new BasicHttpContext(null); try {//from w w w . ja va2 s . c om while (!Thread.interrupted() && !isDestroyed() && this.conn.isOpen()) { this.httpservice.handleRequest(this.conn, context); } } catch (ConnectionClosedException ex) { LOG.debug("Client closed connection"); } catch (IOException ex) { if (ex instanceof SocketTimeoutException) { LOG.debug(ex.getMessage()); } else if (ex instanceof SocketException) { LOG.debug(ex.getMessage()); } else { LOG.warn(ex.getMessage(), ex); } } catch (HttpException ex) { if (LOG.isWarnEnabled()) { LOG.warn("HTTP protocol error: " + ex.getMessage()); } } finally { destroy(); if (this.callback == null) { throw new NullPointerException("The callback object can't be null"); } this.callback.completed(this); } }
From source file:alluxio.worker.job.task.TaskExecutor.java
@Override public void run() { // TODO(yupeng) set other logger JobDefinition<JobConfig, Serializable, Serializable> definition; try {// w w w . j a va 2 s . co m definition = JobDefinitionRegistry.INSTANCE.getJobDefinition(mJobConfig); } catch (JobDoesNotExistException e) { LOG.error("The job definition for config {} does not exist.", mJobConfig.getName()); return; } Object result; try { result = definition.runTask(mJobConfig, mTaskArgs, mContext); if (Thread.interrupted()) { mTaskExecutorManager.notifyTaskCancellation(mJobId, mTaskId); } } catch (InterruptedException e) { mTaskExecutorManager.notifyTaskCancellation(mJobId, mTaskId); return; } catch (Throwable t) { if (Configuration.getBoolean(PropertyKey.DEBUG)) { mTaskExecutorManager.notifyTaskFailure(mJobId, mTaskId, ExceptionUtils.getStackTrace(t)); } else { mTaskExecutorManager.notifyTaskFailure(mJobId, mTaskId, t.getMessage()); } LOG.warn("Exception running task for job {}({}) : {}", mJobConfig.getName(), mTaskArgs.toString(), t.getMessage()); return; } mTaskExecutorManager.notifyTaskCompletion(mJobId, mTaskId, result); }