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

Call method from public class in running thread

I split my program according to the Model-View-Controller pattern so far. For my threads I created a new class: public class MyThreadClass extends Thread { public MyThreadClass() { } public void run() { //Call method…
freeprogramer233
  • 193
  • 2
  • 11
-1
votes
1 answer

which classes can throw the ConcurentModificationException?

I have just found HiddenInterator example, in the Java concurrency in practice book. class ConcurentIterator implements Runnable { // because of final it is immutable, so it is thread safe private final Set v = new…
grep
  • 5,465
  • 12
  • 60
  • 112
-1
votes
4 answers

Some concurrency-design in java

I need to retrieve a huge picture from a server but the server can't do that because the image is too big. I can give "coordinates" so that I can retrieve small parts of that picture. So I split the picture in to 100 tiles and than append 10 tiles…
Selphiron
  • 897
  • 1
  • 12
  • 30
-2
votes
2 answers

Thread.sleep does not pause the app in Android

I would like to pause my android app for 1 second after I inserted something into the Firebase database. For that I use the following code insider a liistener: firebase_DB.child(id).setValue(currentOrder).addOnCompleteListener(new…
VanessaF
  • 515
  • 11
  • 36
-2
votes
2 answers

what does it means when an author says - "two threads try to execute a piece of code at the same time"?

So I am looking at an IBM Article and I couldn't get my head around with the below statements. public class Counter { private int counter = 0; public int get() { return counter; } public void set(int n) { counter = n; } public void…
-2
votes
2 answers

This is a program for creating thread, but showing error can anyone suggest?

Thread Program This program is showing a error marked in the image as red underline. I cant understand that why it occurred. Can anyone suggest me anything?
-2
votes
1 answer

Writing a Java program that uses threads to calculate an expression that ignores order of operations?

I am trying to author a Java program that uses threads to calculate an expression such as: 3 + 4 / 7 + 4 * 2 and outputs Enter problem: 3 + 4 / 7 + 4 * 2 Thread-0 calculated 3+4 as 7 Thread-1 calculated 7/7 as 1 Thread-2 calculated 1+4 as…
-2
votes
2 answers

void lockInterruptibly()

I am trying to understand lockInterruptibly method. What I have understood so far is: void lockInterruptibly() --> acquires the lock if available and performs normal operations. If lock is not available then thread goes in waiting state and while…
raven03
  • 89
  • 6
-2
votes
1 answer

Java ExecutorService pulls tasks all at once

This question is about Java Concurrency. I'm trying to get cmdline to execute another application that takes cmdline arguments in Windows 10 and Server 2012R2. Basically I am trying run the program against 5 files at a time (threadpool is 5). The…
J T
  • 59
  • 2
  • 6
-2
votes
2 answers

Confused about concurrency and Java threads

After reading about concurrency with Java threads, I got a bit confused. Some have claimed (they might be wrong) that Java threads are executed concurrently? If you have 4 CPU's that can do multithreading (can handle 8 threads), how is it possible…
John
  • 71
  • 3
-2
votes
1 answer

Analysing a Thread dump using java

I have a thread dump. Now, I want to know how many threads are running, what is their run time, what is its current state. I don't want to use third party tools. I need a java code which takes dump file as input and shows the o/p.The main purpose is…
-2
votes
1 answer

Transfer values while using threads

I've made three classes and I use one of them to create and start two separate threads for other two classes. How can I pass values within those two classes?
-2
votes
2 answers

Running too many threads - java.lang.OutOfMemoryError

I'm creating too many threads like this in my App for some testing purposes , but sometimes when i set the number of thread too high it crash with a java.lang.OutOfMemoryError: at java.lang.Thread.nativeCreate (Thread.java) at…
EAK TEAM
  • 5,726
  • 4
  • 30
  • 52
-2
votes
1 answer

Android app crashes when class is called that uses a new thread to connect to server

This is the class in question public class ServerLink { private static Context context; private Socket sock; private String IP; private int Port; private InputStream is; private OutputStream out; private String temp; private boolean bTemp; public…
-2
votes
3 answers

My thread doesn't get notified and my program hangs

The following code does not get notify the thread reader it execute the writer and then terminates. Why is it like that? The notifyall should awake all the thread which are at the wait state. public class Testing { public static void…