1,079 questions
0 votes
1 answer
103 views
CompletableFutures, join() and get() vs thread interruption
In my code (Java 17) I am used to handle exceptions from combined CompletableFutures with get() like this: try { CompletableFuture.allOf(someFuture, someOtherFuture).get(); } catch (...
1 vote
1 answer
63 views
Is it thread-safe to use OPCPackage.open in a multi-threaded environment
This is a piece of test code with POI. It reads an Excel file as a template to write data and saves it locally. This code will eventually be executed under a web application, meaning it will be ...
4 votes
2 answers
264 views
javafx MediaPlayer: why are hundreds and thousands of threads running?
I noticed hundreds and thousands of threads running while debugging my javafx MediaPlayer application in Netbeans. So I went to this simple demo code, ran it in the debugger, and again saw hundreds of ...
-1 votes
3 answers
166 views
What is the correct way to safely stop a Thread in Java without using stop()?
I’m learning about multithreading in Java, and I have a specific question regarding how to safely stop a thread. I know that the stop() method is deprecated and unsafe because it can leave objects in ...
-1 votes
2 answers
110 views
How to dynamically allocate threads across multiple services using ExecutorService? [closed]
I have four services that post four types of transactions to a remote server, which allows only 14 concurrent requests at a time. Since Service A and Service B process a high volume of data, they each ...
1 vote
1 answer
165 views
Java multithreading (locks and synchronization) [closed]
I am trying to apply a synchronized block with locks from some old tutorials. The app takes 2 seconds on tutorial, but mine has 4 seconds because of the Thread.sleep(1) part. I don't know why 1ms ...
-1 votes
1 answer
123 views
Java synchronization not working properly
I am trying to implement a custom HashMap for multithreading environment. Why is this giving inconsistent results? I think multiple threads are accessing the put method simultaneously. class Main{ ...
4 votes
1 answer
661 views
Can Virtual Threads improve querying a database in Java?
I wanted to try power of virtual threads in Java in a simple application which consists of many tasks. Each task executes a query agains a database which takes around 10 seconds. My expectation was ...
0 votes
2 answers
121 views
Missed signal in a Java
Can this code ever lead to missed signal? If yes, then how? private Object lock = new Object(); private boolean conditionMet = false; public void waitForCondition() throws InterruptedException { ...
1 vote
2 answers
136 views
How to list all threads of the host OS from within a Java VM?
Is there some API in the Java standard library with which from within a JVM some Java code can be executed that lists all OS threads of the host OS the JVM is running on? In particular, I don't want ...
0 votes
1 answer
159 views
Some questions about JUC
public class TestJUC { private int x; public void actor1(){ x = 1; } public void actor2() { System.out.println(x); } } If thread A executes actor1 method and ...
0 votes
1 answer
92 views
JavaFX TaskWorker will not start [closed]
I am developing a small JavFXML desktop application that includes a TaskWorker. The objective is to run the task worker when a button is clicked, but nothing happens and the taskworker is not called. ...
1 vote
1 answer
63 views
Daemon thread set to enter a command to stop user threads
I need help solving this problem which I have, so if anyone had a similar problem, that will help me a lot. The problem is related to concurrent programming in Java. I have a Ball class, and a Test ...
0 votes
3 answers
145 views
Java thread cannot read changes to data written by main thread?
I have a class Notif (yes i know attributes shouldnt be public): class Notif { public int found; public String reply; public Notif(int i){ found = i; } ...
-3 votes
2 answers
419 views
Thread safe token bucket algorithm
I have below code public class TokenBucketRateLimiter implements RateLimiter { // Maximum number of tokens that can be accumulated in the bucket. private final long threshold; // Time unit ...