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

2D AI Fighting game, I need threads so that the human player and AI can both move at once

//This is the human class //I have added runnable method to make it work but the AI is not moving. import java.awt.Graphics2D; import java.awt.event.KeyEvent; import java.util.Random; import java.awt.Color; public class Human implements…
0
votes
2 answers

JAVA real time consol-control the threads

I am a beginner in programming. I am still learning about threads and more of them. But now I have quite a big idea to write my first program (I mean bigger than simple calculator). I want it to sort files, integrate in one (many copies of one file…
xross
  • 597
  • 4
  • 9
  • 25
0
votes
1 answer

Guarantees for kind of threads for ExecutorService instances

The various ExecutorService instances created by Executors and ForkJoinPool.commonPool() of course have quite different behaviour. If you try the example program below (and its variants) you should see that it only prints "false". Since the services…
0
votes
4 answers

How to make a program wait for a method in java

I am writing a programm that returns me a ArrayList of Strings. Problem is, when I call the method the list is not filled yet so I get an empty list back . I tried it with a thread but now I get a null reference when I call the method. By the way i…
Artur Karaev
  • 41
  • 1
  • 10
0
votes
0 answers

Android app Suspending all threads on class switch

Im currently making an app that has a basic that has a SQLite element to it which I am linking via Intent intent = new Intent(MainActivity.this, MemoActivity.class); startActivity(intent); to the rest of my code. My issue is my app works…
0
votes
1 answer

updating gui from thread(another class)

I have a class called Gui. This is where I place all my labels and buttons. It also contains a button.addactionlistener. When the button is pressed it starts another thread(stopwatch). This is when stopwatch enters a loop which keeps updating the…
Tuyen Phan
  • 43
  • 1
  • 7
0
votes
3 answers

Calling a method on a Thread - it works, but why?

I have the following Thread subclass (simplified slightly for readability): public class ConnectionHandlerThread extends Thread { private Socket socket; private volatile boolean disconnected = false; private ObjectOutputStream out =…
Magnus
  • 17,157
  • 19
  • 104
  • 189
0
votes
1 answer

Apache Thrift reusing connection in different thread

I'm creating a program in Java in which a client can send read/write operations to a node which sends a read/write request to a supernode. The supernode is using a Thrift HaHs server. There are multiple nodes and thus should be able to handle…
Art
  • 147
  • 3
  • 13
0
votes
1 answer

IBM WAS 5.1 / Tread dump analysis: Servlet.Engine.Transports stuck on java.net.SocketInputStream.socketRead0

I am running WAS 5.1 with Sun 1.4.2 Java on a Solaris 10 box. Trying to figure out why the application becomes unresponsive. I see in a thread dump that most threads named Servlet.Engine.Transport[...] remain stuck on this stack…
befo88
  • 43
  • 1
  • 5
0
votes
1 answer

notification bar is not responding while downloading an item using java thread in android

I'm using java thread to download a zip file from an API.when i start download a file,the download progress will be displayed in the notification bar.when i scroll down the notification bar,it have no response.it just hang the device till the…
0
votes
0 answers

Threading running slower in c# than java

My friend and I decided to write similar programs in Java and C# using threads to post data to a website. His Java application runs in about 6 seconds while mine written in C# takes 23 seconds. Looking at my C# code, is there a reason why it is…
0
votes
1 answer

Simultaneously listen to multiple streams in a service

I am working on an Android application which relays data from a socket connection to a Bluetooth interface. For comfortably communicating I have instantiated two BufferedReaders which I want to listen to simultaneously in an IntentService.…
Lukas
  • 756
  • 7
  • 20
0
votes
2 answers

Understanding threads associated with Handler and AsyncTask

AsyncTask must be created and executed from the Main thread and it runs on Worker thread. However, Main thread methods may be invoked in between to publish progress. And what about handler?Can handler be created from any thread?And on which…
user3684678
  • 451
  • 3
  • 7
  • 20
0
votes
2 answers

Executing main class while thread sleeps - java

Can someone help me understand how threads function in java. I have a main class: public static void main(String[] args) { Runnable r = new TestThread(); new Thread(r).start(); executor.execute(r); System.out.println("Hey the thread…
MultiTask70
  • 51
  • 1
  • 9
0
votes
1 answer

Java 'NoSuchElementException' when taking from a queue from threads

I am getting a NoSuchElementException sometimes when removing from a queue. Do I need to use locks/waits/some other delay mechanism? I've provided a rough translation of the code. Thread with Queue public void run(){ while(true){ …