1,078 questions
-1
votes
2
answers
96
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
145
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
107
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
381
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
86
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
121
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
131
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
80
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
54
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
135
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
280
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
162
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
186
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
83
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
70
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 ...