How to execute code after a response in JavaEE

I tried, unsuccessfully, to find a way to run code after response. In my case, a server sends me data in order to let me do my job but this action can be long (send SMS to 5000 contacts and check who received it, for example). The server expects HTTP

How to find a very large file copy status in Java

I have requirement for monitoring the files copying status in a directory and the files are placed continuously into the directory in java. I am planing to use Executor framework to find out individual files copy status and I have written below code

Lock on only one entry point

I am utilizing an ExcutorService to submit tasks to run in parallel. The order of the tasks does not matter. However, the service may change, specifically when the requested size of the pool needs to change. public class Service { private volatile Ex

What is thread termination due to failure?

The javadoc for ExecutorService sometimes refers to the case when a Thread terminates 'due to failure'. However, it is not clear what kind of failure does this refer to. For instance, the single thread executor documentation says that if this single

Pause all Threads running after crossing a given threshold

I have a requirement , where I have a multithreaded java application, and I want to monitor the memory usage as well in the application. I want to pause all the running threads in the executor service , as soon as the memory reaches beyond 90%. Below

Insufficient memory error when using Executors in Java

I am using the Executors framework(fixed thread pool with unbounded blocking queue) to execute tasks concurrently. But when I run a load test with about 10000 tasks created, there is a huge build up of heap memory (2.1 GB) with about 3.5 million Exec

Multithreaded string processing explodes with #threads

I'm working on a multithreaded project where we have to parse some text from a file into a magic object, do some processing on the object, and aggregate the output. The old version of the code parsed the text in one thread and did the object processi

Restarting a java thread

I was wodering why The ExecutorService can actually execute the same Thread multiple times. Because the usual lifecycle of a thread ends on TERMINATED afaik.. So, public class TestThread extends Thread { AtomicInteger counter = new AtomicInteger(0);

Java - get errors propagated from the background thread

I am trying to run a background service as part of my GUI application. I am using an ExecutorService and I am getting a Future back from it. This code shows what I am doing: play.addActionListener( new ActionListener() { service.submit(new Runnable()

Total time taken and average time taken by all subjects

I am working on a project in which I need to measure Total Time taken by program and average time taken by program. And that program is a Multithreaded program. In that program, each thread is working in a particular range. Input parameters is Number

shutdownNow with runtime service

I am using an ExecutorService for a connection task as below: ExecutorService executor = Executors.newSingleThreadExecutor(); Future<ApplicationConnection> future = (Future<ApplicationConnection>) executor.submit(new ConnectThread(crf, connopt

Java - stop all tasks in ExecutorService

I have a few executor services which schedule local tasks such as reading a file, connecting to db etc. These processes do huge amount of logging, which is extensive based on the fact there are many threads running concurrently, writing their own thi

Is there an ExecutorService on the blocking thread?

Is there an ExecutorService that allows an existing thread to perform the executions instead of spawning new threads? Bonus if it's a ScheduledExecutor. Most executors spawn worker threads to do the execution, but I want the worker thread to be an ex

How does closure work for executors?

I have a ScheduledExecutorService and I do a task every 15 mins (in a web application in Tomcat). In a ServletContextListener in contextDestroyed I have done: Runtime.getRuntime().addShutdownHook(new Thread(){ @Override public void run(){ scheduler.s

Reusing java thread through the executor

I am confused on the following: To use threads in a Java program, the simplest way is to extend Thread class and implement the runnable interface (or simply implement runnable). To start the thread's execution. we must call the Thread's method start(

How to obtain the thread ID from a thread pool?

I have a fixed thread pool that I submit tasks to (limited to 5 threads). How can I find out which one of those 5 threads executes my task (something like "thread #3 of 5 is doing this task")? ExecutorService taskExecutor = Executors.newFixedThr

Java: Timer and threads created

I have this question: I have a timer. With scheduleAtFixedRate it creates a new Timer task. In that timer task there is certain code, which may take a while to complete. How can I make sure that Timer won't create new task when the previous one didn'

Know when all discussions are over and deal with exceptions

I am using the Executor framework to kick off several threads using a threadpool i.e newFixedThreadPool. I use threadpool.submit(aThread) to submit jobs to be executed by the threadpool and this works fine however I need to determine when all the thr