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
0
votes
5 answers

There is no console output from thread. Thread doesn't work?

class myRunnable implements Runnable { public void run() { // TODO Auto-generated method stub System.out.println("run"); } } public class TestThread { public static void main(String[] args) { Runnable…
0
votes
1 answer

Android Thread is not ending.It can not start again

In this when the user clicks on the button a thread named "startAThread" starts and the button becomes invisible. After three seconds When the thread has done its work the button again becomes visible. When the user clicks on the button the second…
manish
  • 301
  • 1
  • 3
  • 10
0
votes
2 answers

Java - Force Close Program (with running threads)

In General I want to be able to close my Java application even if there are (non-daemon) threads still running. Is it possible in Java? (Coming from C++ world, that seems like a basic request) Reason I'm building a framework that load external…
Roee Gavirel
  • 18,955
  • 12
  • 67
  • 94
-1
votes
1 answer

Error while working with getLooper() method in android

I am learning threading and concurrency in Android. I have created a basic program where the main thread sends an interrupt to the worker thread to stop the worker thread's processing. The main thread sends the interrupt after 5 seconds. I have 2…
-1
votes
2 answers

How can I see if my code actually makes use of multithreading?

I've been trying to write a Merge Sort algorithm in Java to make use of Multithreading and I'm stuggling to see actually if my code makes use of multithreading, or if I'm just sequentially making thread objects which then go and run the recursive…
eilou
  • 11
  • 1
-1
votes
1 answer

Print numbers from one to ten

I have to print the numbers between one to ten , with ten threads and they got to be consecutive numbers. I mean Thread0 - 10 print 1,1,1,1,1,1,1,1,1,1 then Thread 0-10 print 2,2,2,2,2,2,2,2,,2,2 class A extends Thread { String name = ""; …
-1
votes
1 answer

How to call a method on one running thread but execute it on another running thread?

I am new to java threads. I have an client application that is running on 2 threads: WorkerThread and JavaFxGuiThread. My question is: can i call a method on GuiThread (on press of a button) but execute it on WorkerThread? Note that that at the time…
User
  • 19
  • 3
-1
votes
2 answers

How can this BitSet example print (false,true) or (true, false)?

I am trying to understand the JMM by following the blog post by Aleksey Shipilëv The above example is breaking my mind. Explanation: There are 3 threads the first 2 threads (the 1st and 2nd column) run set() without any locking and the 3rd thread…
ng.newbie
  • 2,807
  • 3
  • 23
  • 57
-1
votes
1 answer

JOptionPane makes my program crash when I join thread

I am writing a program to rename files. Once the user selects the folder the files are processed in a thread. After the thread finishes the program closes the GUI and opens the selected folder. For this reason i'm using the join() method. File…
FabioF
  • 1
  • 2
-1
votes
1 answer

What is the key difference between threads and coroutines in Kotlin?

As new to Kotlin, I am facing a little problem in understanding the difference between thread and coroutine. Can someone make it simple to understand the fundamental them of them? I started learning core concepts of Kotlin programing language…
-1
votes
1 answer

set is not applicable to arguments (int,int)

Hi I am doing a concurrent programming task in java where I'm using an executorService consisting of 10 threads. I have an array containing 100 elements all set initially to 1000. What I am trying to do is I have 2 indexes from the array, and I need…
-1
votes
1 answer

Thread safe for a pool id

I am facing an issue because of RACE condition. Here is the example to better understand the issue. We have a service that stores the birthday greets in GreetingsBox. Every birthday boy have a unique bbId. For every BBid only one GreetingBox is…
Pankaj Sharma
  • 2,185
  • 2
  • 24
  • 50
-1
votes
1 answer

How make threads read from arrays in a certain order

There is an array with strings "A", "B" and "A, B" (there are many repeated). I need to make 2 threads A and B, each of which will independently output its strings in the correct order (as in the original array, general in any). Did I get it right,…
ewl1
  • 17
  • 3
-1
votes
1 answer

Running a compiler in parallel with java.utils.concurrent

I am making a compiler for a language in Java and I want it to compile many files in parallel. I have my class Compiler.java that has the constructor Compiler(String fileName) and the method compile() So to compile a single file in my main all I do…
-1
votes
2 answers

Weird printing behaviour in java threads

I am new to coding and wrote a very simple java code using the concept of threads. I tried printing two statements "good morning" and "welcome" infinitely using two different threads from two classes to see the behaviour of the threads. However…