Questions tagged [java-threads]

For questions related to Java threads, including concurrent data structures, the fork-join framework, atomic classes, thread locking/synchronization, visibility and latency

Examples include:

  • Usages of java.util.concurrent.* data structures
  • Fork-join framework,
  • Atomic classes
  • Thread locking/synchronization, visibility and latency
1037 questions
6
votes
1 answer

Thread not awake when timed wait elapsed in java

I am study wait(long timeout) in java,and in the offcial document I found below description: Some other thread invokes the notify method for this object and thread T happens to be arbitrarily chosen as the thread to be awakened. Some other thread…
flyingfox
  • 13,414
  • 3
  • 24
  • 39
6
votes
1 answer

Suspending Threads while Debugging Java Application IntelliJ

I'm debugging a multi-threaded Java application in IntelliJ. I want to suspend all threads on some breakpoint and resume only selected thread while I step-over the code. I can suspend all threads on a breakpoint, but when I step-over the code from…
6
votes
1 answer

Collect thrown exceptions from CompletableFuture.allOf() execution

Having following scratch code: public static void main(String[] args) throws ExecutionException, InterruptedException { CompletableFuture process1 = CompletableFuture.runAsync(() -> { System.out.println("Process 1 with…
Kamil W
  • 2,230
  • 2
  • 21
  • 43
6
votes
2 answers

Why is the word "join" is used for the Thread.join() method?

I started to do research to find out why the word "join" is used for the Thread.join() method. In fact, it waits for the thread to end on which it is called and pauses the main thread to wait for it so, there is nothing to join. So, its name should…
Stack Overflow
  • 1
  • 5
  • 23
  • 51
6
votes
5 answers

Java multi-threaded program using join() gives wrong results in calculating sum of adjacent numbers

I wrote this simple multi-threaded program to add numbers from 1 to 100,000. When I ran this, I got different values as the end result ( values less than expected 5000050000 ). When I executed the program only using one thread, it gave correct…
6
votes
2 answers

Java - Threads state when performing I/O operations

Suppose a Java thread performs some I/O operation like reading a file with traditional blocking Java I/O. The question is: What is the state of the thread while waiting? I don't know if it is RUNNING (doing some active wait) or WAITING (maybe there…
italktothewind
  • 1,950
  • 2
  • 28
  • 55
6
votes
1 answer

Detecting Application class running on main process on a multiprocess app

I have an Android app that extends the Application class and has many app components (services, activities and broadcast receivers) running along three different process. Each process will instantiate the Application class as soon as it is started.…
Storo
  • 988
  • 1
  • 7
  • 31
6
votes
1 answer

How do I use CompletableFuture.supplyAsync together with PriorityBlockingQueue?

I'm trying to add a priority queue to an existing application that uses ThreadPoolExecutor with a LinkedBlockingQueue via CompletableFuture.supplyAsync. The problem is that I can't come up with a design to assign task priorities that I can then…
6
votes
2 answers

Creating too many threads in Java

I am using threads in my Java application to partially get the data (using network calls). I have a method (which is not in a threaded class), which creates a thread pool with given size (10-15 maximum) and uses them for network calls, and I am…
6
votes
3 answers

Drawing to canvas with user interaction is a bit laggy

I started to study canvas drawing with Android, and i would like to make a simple app. On app start a so called 'snake' starting to move on the screen, when the user taps the screen, the 'snake' changes direction. I achived this easily but there is…
Adam Varhegyi
  • 11,307
  • 33
  • 124
  • 222
5
votes
3 answers

How can I run thread from Main method in Java application?

I believe variables used in static main method should be also static as well. The problem is that I cannot use this in this method at all. If I remember correctly, I have to initiate thread with commnad myThread = new ThreaD(this). The below codes…
user482594
  • 16,878
  • 21
  • 72
  • 108
5
votes
1 answer

After executing wait(), how long does a thread wait if it does not get notified from other threads?

In the below example, as the main-thread is not getting notified from the child thread, it should wait forever. But the main-thread is getting executed and the output of the below example is: c l total: 19900 Why is the main-thread getting…
5
votes
2 answers

How to execute all pending scheduled tasks from a ScheduledExecutorService in Java

I'm using ScheduledExecutorService for requeuing events back into a message queue after sometime has passed. Now I need that after some event is triggered all the scheduled pending tasks of this executor are executed. I have seen that it is possible…
Carlos Andres
  • 417
  • 4
  • 13
5
votes
1 answer

JAVA Thread Dump: Too many waiting threads

I'm facing difficulties in analyzing the thread dump of my vaadin 7.0 JAVA application and an integration layer written in spring MVC. There are too many threads in waiting state which is causing applications to slow down during peak hours and…
Bilal Sheikh
  • 61
  • 1
  • 7
5
votes
0 answers

Watching a directory for new file on Windows

I have a module which has to check particular directory for new file(Create). The file will be created by another system which I don't have control or visibility. I used Java WatchService API and I am able to get event ENTRY_CREATE when there is a…
java_dev
  • 323
  • 6
  • 17
1 2
3
69 70