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
-2
votes
1 answer

How to delete Thread object from an array?

The program I am creating requires an array of thread objects. More specifically I have a class which extends Thread. I am doing this so that each new object created runs on its own thread. If I want to kill the thread and remove it from the array…
Simas
  • 11
-2
votes
4 answers

Thread.stop() is deprecated. But how to use TimerTask instead?

I have started a thread on press of a toggle button. Now I want to stop that thread on pressing that toggle button again. But Thread.stop() API has been deprecated. So, I am getting UnsupportedOperationException. I don't know how to use TimerTask as…
-2
votes
1 answer

How to create a single thread cooldown

I'm finding the way to make a Single thread cooldown but get stuck. In the class who manages the cooldown I created a: private HashMap players = new HashMap<>(); //UUID = Player UUID //Integer = Time in cooldown (Seconds) public void…
-2
votes
1 answer

Where a thread object is created in stack or in heap memory?

Actually I was asked this question recently in an interview , I answered stack , am I right as I thought that threads would be executing methods, but could you please explain as why threads get created in stack or if not then why is it created in…
-2
votes
3 answers

Thread.join() to guarantee execution order

I've read the Thread documentation and looked over a number of examples, but I'm not able to get my code to function properly. I want to guarantee that Threads are executed in the order t2, t3, t1, and am trying to use the join() method to do…
hsotweelvl
  • 85
  • 5
-2
votes
2 answers

Multi Threading perform different task in one Run Method

I'm new at performing Multi Threading. I want to 2 thread with different name. But it is not gonna happen. It takes the last one for the name. Here is my class' code which extended Thread : public class Asallik extends Thread { public…
Musti
  • 27
  • 4
-2
votes
2 answers

what is the difference between the two structures of creating threads mentioned below

Struture 1 : public class Runner { public static void main(String[] args) { Thread t1 = new Thread(new Thread(){ public void run() { System.out.println("value :"); } }); …
v0001
  • 11
  • 1
  • 3
-2
votes
1 answer

OCJP Dumps Thread

Can anyone help me to solve the following problem? public class Starter extends Thread{ private int x=2; public static void main(String[] args) throws Exception{ new Starter().makeItSo(); } public Starter(){ x=5; …
Dengke Liu
  • 131
  • 1
  • 1
  • 10
-2
votes
1 answer

java multi threading - how to synchronise

I have a class with following method public class Test { private List l1; public void send() { for ( x : l1) { //send to receivers and put a log in DB } } } This Test class is used by different…
gany
  • 3
  • 2
-2
votes
1 answer

Possible execution result

public class Messager implements Runnable { public static void main(String[] args) { new Thread(new Messager("Wallace")).start(); new Thread(new Messager("Gromit")).start(); } private String name; public…
user199
  • 107
  • 10
-2
votes
1 answer

offbynull coroutines not consuming all

com.offbynull.coroutines version 1.1.0 consumers only consumes 7500 messages. Please help me understand why this code only consumes 7500 messages instead of 30000. public class DemoProducerConsumer { public static int cnt = 0; public…
Matthew Ong
  • 104
  • 8
-2
votes
1 answer

Run a Web Service at a Particular time of the day EveryDay (Get time From Tomcat parameters )

I have a requirement to send SOAP message to lot of devices everyday at a certain time. I will get the time from a tomcat parameter in web.xml. Something like; DailyTime
Rajkishan Swami
  • 3,569
  • 10
  • 48
  • 68
-3
votes
1 answer

Strange Threads execution Java

I have encountered a strange execution while testing my knowledge about threads haha. I have the following class: public class ThreadTest { public static void main (String[] args){ Thread t7 = new Thread(() -> { while…
Christian
  • 1
  • 3
-3
votes
2 answers

"Variable 'eye' is accessed from within inner class, needs to be final or effectively final"

Alright, so I'm trying to check if a Boolean is True or False and I've initialized it with "true", and then I change it to "false" later. That wouldn't cause problems, right? Well, there is one problem: The code to check that is being run within a…
elias
  • 1
  • 3
-3
votes
1 answer

Searching a list using multiple threads and find element (without using parallel streams)

I have a method public boolean contains(int valueToFind, List list) { // } How can I split the array into x chunks? and have a new thread for searching every chunk looking for the value. If the method returns true, I would like to stop the…