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
-3
votes
3 answers

How to convert Stream> to List?

I've got some code here: public class MapAndFlatMap { public static Stream letters(String s) { List result = new ArrayList<>(); for (int i = 0; i < s.length(); i++) result.add(s.substring(i, i + 1)); return…
DePi
  • 3
  • 2
-3
votes
1 answer

Threads in Java | wait(), notify() and notifyAll()

I have an interface as below(assume it's a Java Interface and methods with void return types) interface FileAccessOperations{ fun requestReadAccess() fun releaseReadAccess() fun requestWriteAccess() fun releaseWriteAccess() } Now I…
Sundeep1501
  • 1,510
  • 1
  • 18
  • 28
-3
votes
1 answer

How to set values to private variable in class where class constructor itself starting the thread?

Below is my source code class where class constructor starting the thread.But in run() it is checking for not null value of a varible.So in order to test the using junit that variable should not be null. public class MainClass extends Thread { …
mae
  • 117
  • 2
  • 12
-3
votes
2 answers

Why start() method is not called before println()?

I am trying to learn about the join() method. In my code when I use DEBUG mode it first calls the run() method, but when I run it my output differs. When we try to start a thread using start() method, the run() method will be called internally and…
Heyyou
  • 151
  • 1
  • 13
-3
votes
2 answers

Run Thread Until 2 Integers are the Same

I want to check in the background if 2 Integers are the same. When they are the same I want the thread to stop and I want one of my function to be called. How can I do this?
-3
votes
3 answers

threads still running after system.exit()

I'm learning about multi-threading in Java and was experimenting with threads. I came up with a sort of racing condition code (sort of... excuse this noob) where 2 threads work in a loop (100 times) and races to change a static variable. The goal is…
-3
votes
1 answer

Concurrent programming Java Threads

I have been given a task to do for class however we have only been taught to a certain extent and this has left a knowledge gap. we have been asked to complete the remaining code to some we had done in class, the tutor has given a description of…
cozbouk
  • 17
  • 1
  • 6
-3
votes
1 answer

How do we simulate the test cases for RMI concurrent call of remote object by two clients

How do we simulate the test cases for RMI concurrent call of remote object by two clients. The same Remote object over the same method is being called by the two clients considering that the methods are not synchronised. I am aware that this will…
Maninder Singh
  • 177
  • 1
  • 9
-3
votes
2 answers

Add graphics on a Jpanel Object with Thread

I want to add graphics in this program. The graphics will be drawn on "drawPanel" object. I have to use thread here. No idea for drawing in a Jpanel object with thread. What will be the good efficient way to draw graphics on that Jpanel Object? How…
-3
votes
3 answers

Java class implements Runnable, creates new thread, then returns strange results. Why?

I'm learning about Java and it's quirks. What's going on here? public class myThread implements Runnable { String msg = "yes"; public void run() { this.msg = "No"; } public static void main(String[] args) { …
Jeremy
  • 11
  • 3
-3
votes
1 answer

Synchronized method not blocking other threads

I've a singleton class like this: private static StringsHandler INSTANCE = null; private int count = 0; //I have 2 methods so I don't have to be sending/checking nulls on getInstance //once it's created public static void createInstance(List
Artemio Ramirez
  • 1,116
  • 1
  • 10
  • 23
-3
votes
2 answers

run() method doesn't get called from a Runnable implementation

I'm having a trouble with Runnable and Thread implementations. I have this abstract class, that can not be modified: abstract class Ordenador { ... protected Ordenador(String nombre, int[] array) { ... } protected void…
allnex
  • 335
  • 3
  • 12
-3
votes
4 answers

Thread Sleep Makes Other Threads Wait

I have a task where while generating a random password for user the SMS should go after 4 MIN, but the welcome SMS should go immediately. Since password I am setting first and need to send after 4 MIN I am making that thread sleep (Cant use…
goodyzain
  • 683
  • 2
  • 8
  • 21
-4
votes
3 answers

Multithreading in java interrupt()

I am trying to find element using two threads as soon as 1st thread finds the element it will interrupt other thread i have divided the array into 2 parts (0-length/2) & (length/2 -n) to search over it. But I am not able to achieve the…
nlogn
  • 1,034
  • 4
  • 11
  • 17
-5
votes
1 answer

Why isn't equals() method working on Threads?

public class Test { public static void main(String[] args) { Thread t1 = new Thread(); Thread t2 = new Thread(); Thread t3 = t1; String s1 = new String(); String s2 = new String(); …
1 2 3
69
70