1,079 questions
0
votes
1
answer
91
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
62
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
254
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
119
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
646
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
157
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
91
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
58
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
141
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
408
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 ...
0
votes
0
answers
235
views
Tomcat catalina.policy file provides security policies to JVM in JDK 21 where Security Manager is deprecated
I have the following JAVA 21 code running within a Tomcat 9 Server where a method is invoked using a CompletableFuture:
CompletableFuture.supplyAsync(this::makeHttpCall);
The method makeHttpCall ...
0
votes
1
answer
216
views
Impact of high CPU usage on a background thread execution in Java
Context
There are many ways of creating a "background thread" in Java. I want to spin off exactly one thread that keeps running in the background. I'm using ScheduledExecutorService for this....
-1
votes
2
answers
106
views
Detached entity passed to persist Error in spring jpa With Scheduler threads
i have getting this exception when i try to save and flush Object From Class A. (spring version 2.7.8)
@Table(name= "table_a")
@Entity
@Data
public class A {
@Id
@GeneratedValue(strategy=...
0
votes
1
answer
75
views
What problems can I have with spawning a set of new threads from Servlet and what alternatives exist?
For simplicity, I will omit some details and try to highlight the main point:
I have a servlet that consumes users' requests, when a user sends a request I need to gather data from many endpoints. One ...
1
vote
0
answers
81
views
How to catch any exceptions that occurs in a Future that is being interrupted in Java?
I am trying to implement a timeout on a save operation on a PDF document. I have this piece of code so far:
private Boolean saveDocumentWithTimeout(Path path, PDDocument pdDocument) {
...
0
votes
0
answers
176
views
Can't stop java application wrapped as windows service using procrun
I am trying to wrap a java application as a windows service. I use procrun to do so and it works fairly good (I can install the service and start it, the application works fine), but when I try to ...
1
vote
1
answer
99
views
Confusion about thread synchronization
public class Interview implements Runnable {
int b = 100;
public synchronized void m1() throws Exception {
//System.out.println("-----");
b = 1000;
Thread....
0
votes
1
answer
204
views
why grpc java thread is blocked without any lock or synchronization syntax around the blocked line
At application startup, I've noticed an extreme delay in the initialization of my gRPC client stream. Through thorough examination via logs and jstack, I've identified that the 'grpc-default-executor-{...
1
vote
1
answer
129
views
How can I identify which code in my Android application initiates the creation of threads using the Android Profiler
I am working on a plugin-based application which has different plugins. Each plugin is independent of the others. I am also using the Google Places API as a plugin in it. There is an option to refresh ...
0
votes
0
answers
76
views
Exception in Execute Select java.lang.IllegalThreadStateException: Thread is already started
Getting Excpetion in Execute Select java.lang.IllegalThreadStateException: Thread is already started when we are trying to execute a select statement in a sql server through java below is the code ...
2
votes
1
answer
389
views
Spring @Async architecture for scheduled, long running api calls
I need to solve the following problem, described exemplary:
My Spring application checks every minute if there is a new job. If there is a job, it subtasks should be run in parallel. They are mostly ...
-1
votes
1
answer
278
views
Function for making the code wait in javafx
Im new to using javaFx and programming in general so this might be a stupid question. Im trying to make a function that makes the thread wait without crashing the program which would result in ...
0
votes
0
answers
49
views
How does the class Exchanger in Java actually work?
I'm still very new to how Threads work in Java and I got an assignment to recreate the Exchanger class based on its functionality.
I read the documentation and I understand what it is supposed to do, ...
1
vote
0
answers
53
views
Can anything external to the JVM interrupt Process.waitFor()?
I've been using roughly the same utility code to handle executing an external Process for at least a decade. Recently a customer hit a case where the following ~code was interrupted:
try {
int ...
2
votes
0
answers
362
views
Java 21 virtual threads and Guava striped locks replacement
Striped locks, as popularized with Google Guava java library, allow the user to trade between required concurrency and memory footprint. However, I wonder if this is still true with Java 21 virtual ...
1
vote
3
answers
161
views
Unable to understand the time consumption by Java threads
I created a 1000 threads and each thread takes about 10 seconds to finish. During these 10 seconds the thread doesn't sleep but does a simple math operation.
However, the program still finishes under ...
0
votes
1
answer
81
views
How to return a list of results of finished threads?
I have written the program for thread factoring. Tests are working for every method, except result. As I understand, I'm including threads that threw and exception, but not including finished threads.
...
6
votes
1
answer
2k
views
Spring boot virtual threads -Djdk.tracePinnedThreads=full causes tasks to hang
Not sure if this is a spring or java problem. If I run the test with the below setup including -Djdk.tracePinnedThreads=full the test hangs. Without it it runs fine. Any ideas why this might happen. ...
0
votes
0
answers
79
views
Spring API throw interrupt signal when using Thread.sleep()
I'm using Spring Boot to build my service. I have an API that will scan the database to update status. It follows:
Step 1: Scan the database to update status
Step 2: If have no data then sleep for 5 ...
-2
votes
1
answer
120
views
Only one of my threads executes when trying to use a Semaphore [closed]
To my understanding, java.util.concurrent.Semaphore allows me to specify how many threads can use a resource at once. A thread can use Semaphore.acquireUninterruptibly() to consume the limited number ...
0
votes
1
answer
113
views
How to queue threads in java
public void meow(){
synchronized (Cat.class) {
sout("meow");
}
}
Let's say program has cat1 cat2 cat3 objects.
If cat1 wants to run the meow function first, let ...
0
votes
0
answers
30
views
Why are changes made to java.util.concurrent.CopyOnWriteArrayList not reflected in paintComponent?
I'm working on a Swing application where I have a list of shapes (List shapesToDraw1) that I update from a non-EDT thread using SwingUtilities.invokeLater(). The code for updating the list is executed ...
1
vote
1
answer
184
views
Allow concurrent executions of two methods but not both at the same time
I have two instance methods method1 and method2 of an singleton object. method1 can be run concurrently by separate threads. Meaning we can have 5 threads each running method1 at the same time or 1 ...
0
votes
1
answer
58
views
Creating a Thread for Socket Communication with Command Processing
I'm working on a Java application that involves socket communication, and I'm trying to create a Thread subclass,calling it CommandThread, which reads commands from a Socket. The valid commands ...
0
votes
2
answers
2k
views
Create separate thread Pools for a pool of Platform Threads in java
I want to create pool of virtual threads running on separate pool of Java Threads.
Here's the architecture I am trying to create:
This is to enable me to create separate pools to run batch tasks in ...
1
vote
2
answers
393
views
Looking for clarity on Thread.sleep() method
Thread.sleep() method puts the thread that is running it to sleep.
thread.sleep() statement in the below code will be run by main thread, 'thread' in the below code is an user defined thread. Why is ...
0
votes
0
answers
51
views
Unreliable JPEG transfer over socket in Java [duplicate]
I am currently working on a project aimed at developing a screen share program. The program involves a client that can act as either a sender or receiver and a server that facilitates the distribution ...
0
votes
0
answers
2k
views
How to implement a rate limit in Java
I have a spring boot application which serves requests from different users. Some requests might take long time and eventually cause a timeout. If a user would make lot of such calls, the entire ...
0
votes
2
answers
876
views
Synchronized Statements in Java Thread
I'm reading the Thread Topic on the official tutorial and I'm trying to understand the Intrinsic Look.
I understand the different basic between synchronized method, synchronized statement and ...
2
votes
1
answer
107
views
call join() after interrupt() in Thread Java
I'm learning in Thread Java and I follow the tutorial on official docs java
This example combines various methods: join(), sleep(), interrupt() and , start()
public class SimpleThread {
// Display ...
0
votes
1
answer
78
views
AspectJ in back-end Java thread with POM based weaving [duplicate]
I have a back-end thread, which I created inside start method of JBoss Mbeans:
public interface HScannerServiceMBean {
public void create();
public void start();
public void stop();
public ...
1
vote
0
answers
41
views
Memory Leak in JAVA/FLEX application
After shut downing my application I get a memory leak error message :
<<Stopping Ebus Manager...
24-Oct-2023 14:36:22.840 WARNING [main] org.apache.catalina.loader.WebappClassLoaderBase....
1
vote
2
answers
143
views
Call a synchronized method with a new thread in a synchronized method
We have a task to perform, dummyMethod.
private synchronized void dummyMethod(){
Log.d("debug", "do nothing in dummyMethod()")
}
We run that task several times.
private ...
1
vote
2
answers
73
views
print number in order with thread
I want create two thread first one even and second one odd and I want have synchronized list to add this number and at last print number in order this is my codes
@Override
public void run() {...
1
vote
1
answer
184
views
Which JVM dereferenced object cleanup implementation works best?
Assuming an object K is associated with a scarce system resource (e.g. binded to an open port on localhost UDP, of which only 65535 per machine is available). A JVM application is required to create ...