Tagged Questions
0
votes
0answers
4 views
Make JUnit test fail on System.exit somewhere in another thread
I have a functional test of Multi-threading system. The problem is that the system uses System.exit so my junit test doesn't catch this errors. So I want my test fail if somewhere System.exit was ...
1
vote
2answers
63 views
Java multithreading with wait and notify
I have this piece of code
public MultiThreadedSum(ArrayBuffer ArrayBufferInst)
{
this.ArrayBufferInst = ArrayBufferInst;
Sum = 0;
Flag = false;
StopFlag = false;
}
public ...
-2
votes
0answers
10 views
in RejectedExecutionHandler impl , what's the difference between executor.getQueue().put(rejectedTask) and executor.execute(rejectedTask) [closed]
class RejectedExecutionHandlerImpl implements RejectedExecutionHandler {
@Override
public void rejectedExecution(Runnable rejectedTask, ThreadPoolExecutor executor) {
...
10
votes
8answers
183 views
Tips to prevent deadlocks in java
I am studying java threads and deadlocks, I understand deadlock's examples but I wonder if there are general rules to follow to prevent it.
My question is if are there rules or tips that can be ...
2
votes
2answers
50 views
How do Synchronized Lists Work?
I am not sure I understand Synchronized Lists in Java. Suppose I have the following:
List<Integer> numbers = Collections.synchronizedList(new ArrayList<Integer>());
// Assumption: This ...
0
votes
0answers
15 views
Stream management in java - Client/Server sending and recieving files.
I have trouble with my streams. I'm using multi-threaded client and server so that i could upload or download files one after another, but after getting the first file ( doesn't matter if I send a ...
5
votes
1answer
67 views
What is the most efficient way to create additional threads from a thread?
Question
What is the most efficient way to create additional threads from a thread?
Context
I am redesigning an application to be more efficient. One of the largest improvements will be running ...
0
votes
1answer
37 views
ExecutorService no performance gain recursive determinant Java
I've read similar questions where the problem was usage of synchronized methods (like Math.random() ) or the work was too little to justify the overhead, however I don't think this is the case here.
...
4
votes
4answers
103 views
How to implement a growing list
I am attempting to iterate through the same data, but want to only load the data if it is necessary. I also want to reuse the fetched data in multiple, concurrent, iterators.
Is there an object, or a ...
3
votes
2answers
80 views
Explicit Locks vs Implicit Locks
Is using Locks (java.util.concurrent.locks.Lock) instead of keyword synchronized + method wait() and method notify() totally the same?
Can I thread-safely program using locks (explicit locks) rather ...
1
vote
6answers
85 views
Why i am getting following output from this java program?
class MyThread extends Thread
{
MyThread()
{
System.out.print(" MyThread");
}
public void run()
{
System.out.print(" bar");
}
public void run(String s)
...
0
votes
4answers
54 views
Start a thread in a loop
I wonder know how to start a thread for the 1st time in a loop :
Example:
while(something)
{
/*
...
Some codes
...
*/
thread.start();
}
The problem is that I get this error :
...
0
votes
2answers
37 views
how to set timer before doing a action?
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
char[] pass = pass1.getPassword();
String passString = new String(pass);
String l = ...
0
votes
0answers
36 views
Looking for a priorityqueue-like alternative to ReentrantLock for stealing locks from other threads
I have a set of wrapped ReentrantLocks that have unique integer ids, where I require threads to acquire lower-id locks before they acquire higher-id locks in order to prevent deadlock. Three of the ...
4
votes
3answers
71 views
Do threads get automatically garbage collected after run() method exits in Java?
Does a thread self-delete and get garbage collected after it runs or does it continue to exist and consume memory even after the run() method is complete?
For example:
Class A{
public void ...
0
votes
1answer
85 views
Removing an item from ArrayList in a separate Thread in Java
I have a long running loop.
Inside the loop I have another loop to iterate (using iterator) on a arrayList.
If a condition is met while looping through array list I initiate a thread while passing ...
2
votes
0answers
68 views
Thread continues to run after run() method
I have an issue with playing sound in my game. When the Thread that handles the sound playback exits it's run method it doesn't terminate/end/stop. I know it's this method that causes the problem, ...
1
vote
1answer
74 views
how many thread can ran on a cpu at a time
I want to know that how many thread ran on a cpu for a single application at the same time time?
I do a simple code like
import java.awt.SystemColor;
import java.util.Date;
public class Threadcall ...
0
votes
1answer
41 views
Running a method from an object in another Thread
I have LibGDX Application in which I paint and a Thread for Client or Server. Connections are done using Kryonet. When your opponent creates does something a message is recieved linke so:
public void ...
0
votes
2answers
42 views
When i click on the progress bar close button it should ask the confirmation and stop the progress bar background task
I have added a progress bar in my java swing application. When i click on the progress bar close button it should ask for confirmation and stop the progress bar background task when the user select ...
0
votes
1answer
28 views
Can I retrieve the task running in a ScheduledExecutorService without keeping its reference?
I am currently modifying an application to use a ScheduledExecutorService in place of a Timer and I used to access the scheduled task with a Map I kept, and it allowed me to cancel() the task as well ...
2
votes
4answers
57 views
Synchronization on instance variable
In the below example, lock is obtained on instance variable employee (not on this), but still Threads of TestClass1 are getting locked while entering synchronized block. Any advice why is this ...
3
votes
4answers
66 views
How pause and then resume a thread?
I state that I read about thread, but I've never used.
So I ask to you :)
I have two thread: A and B,
where A manages the GUI, and B manages the logic.
I would start with A.
Then when A draw the ...
0
votes
2answers
53 views
wait for thread to finish (without “waiting”) before next iteration
I'm checking for certain condition inside a loop, if that condition is met then I want to initiate a new thread.
Within the thread I make an update, that update will have effect on the condition on ...
0
votes
2answers
30 views
Daemon threads terminate in jvm
i read about Daemon threads in internet i found it's not terminate either we JVM terminate
Is it mean after we close our java program also Daemon threads can run?
"Daemon threads die when the Java VM ...
1
vote
1answer
26 views
What happens to terminated tasks in a ScheduledExecutorService?
I am currently modifying an application to use a ScheduledExecutorService in place of a Timer and I don't know what to do with my old Timer.purge().
How are things handled with an Executor? Do I have ...
0
votes
1answer
74 views
How to access GUI from another thread
What I am trying to accomplish is setting a text field from another thread. my program has a button and when i click it a new thread start running and gets something from a socket afterwards I want to ...
0
votes
2answers
64 views
Thread java - Can it be reinitialized?
I m coding a little game whose goal is to manage a mall. My problem is the animation.
Actually, my colleague created the class Animateur that extends Thread and implements Runnable.
In my frame, I ...
0
votes
1answer
34 views
Java Timer synchronize with GUI
I'm trying to do an incremental display of a Component because it takes too much time to make all the calculations. So i don't want to freeze the graphic interface i'd like to display my image ( a ...
0
votes
2answers
49 views
Having multiple clients connecting to Java Server
I'm creating a simple socket server using Java. I am able to connect one client at a time, I tried to implement Threads to handle multiple client. In my Server constructor I created a thread that ...