Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
-1 votes
1 answer
103 views

Make a `Callable` of my `Runnable` in Java

I have some tasks defined as Runnable objects. I want to invoke those tasks by using the invokeAll or invokeAny methods on ExecutorService. The problem is that those methods take a collection of ...
Basil Bourque's user avatar
1 vote
1 answer
538 views

Why do threads through a loop give an error when with Executor

The sample code is taken from the Java Philosophy 2015 book and it used Java SE5/6. I used JDK11, maybe this code is not suitable for the new version, but why? public static void main(String[] args) { ...
General Esdeath's user avatar
3 votes
1 answer
690 views

Android Thread Execution Slows Down when screen locks

Iam running this procedure to download some data and insert them into the database. The total procedure takes around 5 minutes. I noticed that while downloading, when the phone locks the screen and ...
Nick's user avatar
  • 2,928
9 votes
1 answer
2k views

"Runnable::run" - How is this creating an Executor instance?

I'm working on a project where the following line is used to create a test Executor member variable instance: private Executor executor = Runnable::run; The code runs and compiles but I don't ...
T.R.'s user avatar
  • 171
0 votes
1 answer
1k views

Executors not completing all the task

Hi I am trying to run below code, and after executor is terminated I am expecting the count of remaining task to be 0, but for some reason it's more then 100 when it satisfy below condition. while(...
Jigar Naik's user avatar
  • 1,996
3 votes
1 answer
293 views

Method reference as an Executor implementation

I have been studying an example java code written by someone and faced the following snippet: Runnable runnable = () -> System.out.println("Thread name: " + Thread.currentThread().getName()); ...
Cyril Silver's user avatar
0 votes
0 answers
308 views

Executor in java with Runnable Object

I was trying to learn the Executors and is having doubts. Assuming that I has 2 Runnable objects Socket1Write and Socket2Write which have a run method. Run methods have an infinite loop which will ...
Jineesh Lk's user avatar
2 votes
1 answer
150 views

Java - ExecutorService : How to re run "wait state" thread

I'm using ExecutorService like, ExecutorService executorService = Executors.newFixedThreadPool(5); for(int i = 0 ; i < 5 ; i ++){ executorService.submit(new MyRunnable()); } and my Runnable ...
botem's user avatar
  • 348
1 vote
0 answers
269 views

recycle Runnable object, how can i do it?

in my Android App I'm using a single thread executor and every 300 milliseconds I create a new MyRunnable and I call the method execute() of my SingleThreadExecutor. Now my goal is to recycle the ...
aeroxr1's user avatar
  • 1,074
0 votes
0 answers
75 views

Android Threads are automatically suspended

I'm trying to make some calculations using Multi threading. At maximum I will have to make 100 different calculations. Even when I tried to balance the start of threads from 10 each time, I am having ...
user3111591's user avatar
3 votes
2 answers
13k views

java executor delay not working

Ok so I have tried 3 different options of delayed executors for a void/runnable/timertask that I want to run after 5 seconds but all the codes I used didn't work. They would immediatly run the code. ...
jeroen's user avatar
  • 47
0 votes
1 answer
286 views

Android: Make threads run queued one by one in AlarmBroarcastReceiver

Kindly ask for your advice, i'm new to Android programming. I'm writing an alarm-clock-like software, and use public class AlarmManagerBroadcastReceiver extends BroadcastReceiver to catch alarms set ...
lxs's user avatar
  • 3
1 vote
2 answers
4k views

How to know when a thread stops or is stopped?

I have the next code: Executor exe = Executors.newFixedThreadPool(20); while (true) { try { exe.execute(new DispatcherThread(serverSocket.accept())); continue; } catch (...
zepol's user avatar
  • 309
2 votes
4 answers
2k views

Should I use an Executor to run only 1 Runnable? When to use an executor?

I am making a server, and the server creates a thread for each client that connects. That thread will have an open inputstream which it will monitor for incoming messages. The Runnable of that thread ...
efronberlian's user avatar
6 votes
6 answers
14k views

Schedule Java task for a specified time

I would like to be able to schedule a task at a specific time in Java. I understand that the ExecutorService has the ability to schedule at periodic intervals, and after a specified delay, but I am ...
Ray's user avatar
  • 4,869