java-threads Questions

5

Solved

I wrote this simple multi-threaded program to add numbers from 1 to 100,000. When I ran this, I got different values as the end result ( values less than expected 5000050000 ). When I executed the ...
Jaimeejaimes asked 27/5, 2018 at 22:3

1

Solved

I've found these in my hs_err_pid.log. Events (10 events): Event: 2603309.010 Thread 0x00007ff2c800c000 DEOPT UNPACKING pc=0x00007ff34aaddf69 sp=0x00007ff3409e88a8 mode 2 Event: 2603310.108 Threa...
Rocketeer asked 8/4, 2018 at 10:3

1

Solved

Suppose a Java thread performs some I/O operation like reading a file with traditional blocking Java I/O. The question is: What is the state of the thread while waiting? I don't know if it is RUNNI...
Gosnell asked 25/2, 2018 at 0:18

1

Solved

As part of the putative JDK 10 this JEP 312: Thread-Local Handshakes was proposed. I've tried to grasp its description, but I am still not confident that I got the idea properly. Is it essential...
Brena asked 10/11, 2017 at 12:29

4

Solved

While learning Java 9 features I came across a new method of Thread class, called onSpinWait​. As per javadocs, this method is used for this: Indicates that the caller is momentarily unable to p...
Prosperity asked 19/6, 2017 at 4:43

2

Solved

Imagine I have 3 threads with a wait condition, and a 4th thread with a notify condition. Now, all 3 wait threads run and enter a waiting state. Once this is done, the 4th thread runs and ca...
Sole asked 26/7, 2017 at 8:43

2

Solved

Parallel programming was possible in Java only from Java 7 with the advent of Join/Fork framework. Let's say in Java, using ExecutorService I create a thread pool of say 4 threads and submit t...
Preciosa asked 4/7, 2017 at 9:15

12

Solved

I have 2 matrices and I need to multiply them and then print the results of each cell. As soon as one cell is ready I need to print it, but for example I need to print the [0][0] cell before cell [...
Gi asked 20/5, 2009 at 8:4

6

Solved

What is the difference between thread state WAIT and thread state BLOCKED? The Thread.State documentation: Blocked A thread that is blocked waiting for a monitor lock is in this state. Waiting A t...
Numerable asked 28/3, 2013 at 11:18

2

Solved

Apologies for this repeated question but I haven't found any satisfactory answers yet. Most of the question had their own specific use case: Java - alternative to thread.sleep Is there any better o...
Glib asked 24/7, 2013 at 6:25

6

Solved

How do multiple threads in Java handle working with a single object reference passed to them? Do they make a copy of the object and then use it, or do they use the same one? Any technical expla...

1

Solved

Listing 3.15. Class at Risk of Failure if Not Properly Published. public class Holder { private int n; public Holder(int n) { this.n = n; } public void assertSanity() { if (n != n) t...
Loess asked 20/10, 2016 at 2:41

1

Solved

This is a Java Program to Find The Number with Largest Divisors from 1-500000. public class Medium2 { static int count1 = 1; static int count2 = 1; static int big_count = 0; static int bi...
Enclosure asked 10/10, 2016 at 10:36

1

Solved

TL:DR ExecutorService executorService = Executors.newFixedThreadPool(8); in debug runs concurrent, but in normal runtime it starts concurrent, but later runs in single thread. I have some code whe...
Espinosa asked 13/7, 2016 at 14:31

1

Solved

I'm wondering if there is a way to shutdown a Java ExecutorServiceand allow all submitted tasks to finish while not blocking. to be more specific, I want to schedule a Runnable with a delay and co...
Geniculate asked 17/5, 2016 at 13:23

1

class Test { boolean isFirstThread = true; private synchronized void printer(int threadNo) { if(isFirstThread) { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTra...
Hounding asked 22/4, 2016 at 19:16

3

Solved

I have a code where 4 threads run at the same time. I want to wait until all these 4 threads will be finished. And only after that to continue the app flow. I tried two approaches: Thread#join(), ...

2

Solved

I'm using a source code analyser that pointed out that notifyAll() should not be called within a Thread instance. I'm trying to articulate this to management, but I can't come up with an explanatio...
Curmudgeon asked 25/2, 2016 at 15:46

1

Solved

I'm trying to add a priority queue to an existing application that uses ThreadPoolExecutor with a LinkedBlockingQueue via CompletableFuture.supplyAsync. The problem is that I can't come up with a d...

2

Solved

I know that implements Runnable is preferred over extends Thread in Java threads as it allows us to extend some other class if it is required. But if this is the case, does extends Thread als...
Dehypnotize asked 22/1, 2016 at 11:22

2

Solved

I am using threads in my Java application to partially get the data (using network calls). I have a method (which is not in a threaded class), which creates a thread pool with given size (10-15 max...

6

Solved

What is the difference between Service, Async Task & Thread. If i am not wrong all of them are used to do some stuff in background. So, how to decide which to use and when?
Litterbug asked 16/7, 2010 at 11:35

3

Solved

I started to study canvas drawing with Android, and i would like to make a simple app. On app start a so called 'snake' starting to move on the screen, when the user taps the screen, the 'snake' c...
Cammie asked 22/7, 2015 at 7:37

4

Solved

public class ObjectCounter { private static long numOfInstances = 0; public ObjectCounter(){ synchronized(this){ numOfInstances++; } } **public static synchronized long getCount(){ return n...

4

If I understand correctly the stack is for local primities and references to the objects in the heap. So what happens if you have more than one threads? Do they share the same stack space at the ...
Hardship asked 16/5, 2015 at 0:40

© 2022 - 2024 — McMap. All rights reserved.