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

How can I calculate how many times function has been called for each thread?

How can I calculate how many times function has been called for each thread? So suppose that there are many flows, which are calling the same function. I have to change them all in order to pass some parameter, which will keep the the number of…
Vardan Hovhannisyan
  • 1,101
  • 3
  • 17
  • 40
0
votes
2 answers

Setting "flags" between threads in Java

I have a class which connects to a server as below. @Override public void run() { while (running) { try { msgHandler.log("Connecting to " + host + ":" + port); Socket s = new Socket(host, port); if…
Saad
  • 915
  • 9
  • 19
0
votes
4 answers

Detecting which Java thread is intruding my method execution

I am facing a complicated problem with my current code (which is pretty huge). To achieve my task, we had to make many method calls around 100-120 method calls (Please don't ask me why I am doing so, it is totally decoupled implementation). To give…
Rengasami Ramanujam
  • 1,858
  • 4
  • 19
  • 29
0
votes
1 answer

Unable to obtain GPS co-ordinates in background (Using Handler)- Android

I am trying to obtain GPS co-ordinates via a handler. Below is the code : final Thread ObainGpsBackground = new Thread(new Runnable() { @Override public void run() { try{ String…
TechFrk
  • 185
  • 2
  • 2
  • 15
0
votes
0 answers

InterruptedException in Producer/Consumer Multithreading

I have a Producer/Consumer Application , where i am reading from a JMS queue and passing the message to multiple consumer threads for processing.I am using blocking Queue for the same How should i handle Interrupted exception in either case?
hisham
  • 1
0
votes
1 answer

How to wait a thread to finish to back to the previous code

I have a question regarding threads. I have a method that reads an Excel spreadsheet and saves the data in a database. However, this method also checks the contents of a cell is an expected value, and if not, a frame must be called for the user to…
oitathi
  • 153
  • 2
  • 3
  • 17
0
votes
2 answers

jsp : Could I change the order of render/execution

I am working on jsp, What I am trying to implement is quite simple. do some time-consuming work with Java while processing, show users the spinner So I have implemented like below <%@ page contentType="text/html; charset=UTF-8" %> <%@ page…
Juneyoung Oh
  • 7,318
  • 16
  • 73
  • 121
0
votes
1 answer

Future related clarification in Java

I have below method in my application and it's looks working fine.. but i m not sure how it is... ArrayList arr = new ArrayList(); Collection> futures = new LinkedList>(); RestCallThread thread = null; HttpHeaders header =…
0
votes
1 answer

Why do wait and notify function not working properly on same class lock

Why do wait and notify function not working properly on same class lock? Please see check below code for wait and notify functionality and its output. Output: Thread-1 Thread-2 Thread-2 after notify Expected Result: Thread-1 Thread-2 Thread-2…
0
votes
2 answers

Java call child class method in multithreading

public abstract class Event implements Runnable { public void run() { try { Thread.sleep(delayTime); action(); } catch(Exception e) {e.printStackTrace();} } } I have this event class above, when I try to start the…
0
votes
1 answer

Multithread applications on MPP architecture

In short: Does it worth the effort to add multithreading scalability (Vertical scalability) on an application that will run always in a MPP infrastructure such Tandem HPNS (Horizontal scalable)? Now, let me go deeper: I’ve seen on many places the…
Marco Vargas
  • 1,232
  • 13
  • 31
0
votes
2 answers

Java thread stuck after join

I have this Transmitter class, which contains one BufferedReader and one PrintWriter. The idea is, on the main class, to use Transmitter.receive() and Transmitter.transmit() to the main socket. The problem is: public void receive() throws Exception…
João Vilaça
  • 601
  • 1
  • 6
  • 13
0
votes
1 answer

how to call a method once an endless thread is stopped manually

I have an endless thread running in my code. This thread creates UDP read methods and listens on the connection endlessly. What I want to do is to execute a piece of code once I stop the thread execution manually (by clicking the stop button in…
Ashish
  • 13
  • 4
0
votes
1 answer

Threads in Java with while loop

We have 2 Threads in Java: Thread 1: … public void run() { while (Share.COUNTER<8) Share.COUNTER++; } … Thread 2: … public void run() { while (Share.COUNTER>-7) Share.COUNTER--; } … The question is: Which thread is going to be…
Blnpwr
  • 1,793
  • 4
  • 22
  • 43
0
votes
1 answer

Java Bluetooth How To Run Process In Background

I am attempting to receive data on a phone over Bluetooth, and I am using Android Studio to attempt this. The problem is, when I run a process that listens for incoming data, I believe that the program stops at the process and waits, not allowing…