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

ThreadPool in java with two queue

Problem: I have to manage a post office with two queue, one is managed by the programmer(the first queue), the other is implicit in the ThreadPool. So, each thread has to pass in the first queue, then in the second, then should be executed. I have a…
-1
votes
1 answer

When a thread is dead what happens to its object?

Following code is giving me NullPointerException. class MT extends Thread{ public void run(){ } } public class ThreadGroupDemo{ public static void main(String[] args) throws InterruptedException{ MT t = new MT(); …
-1
votes
1 answer

Why aren't Java threads both lightweight (like green threads) and multi-core capable? (backed by an internal native fixed size native thread pool)

Back in java 1.1 all threads were running on a single core (not taking advantage of machine's multiple cores/CPUs) and scheduled by JVM in user space (so called green threads). Around Java 1.2 / 1.3 (depending on the underlying OS), a change was…
morgwai
  • 2,513
  • 4
  • 25
  • 31
-1
votes
1 answer

Design Executor service based on task weightage

Need help in designing my executor service or use existing if these functionalities are available. Let say, I have a total computational capacity up to 10. I'll assign each task some weightage (2,4,6). Submitted tasks should run based on weightage…
yuvaraj
  • 149
  • 1
  • 1
  • 10
-1
votes
2 answers

What's the best way to declare a new thread via an anonymous class?

I've been checking some technical stuff about Threads in Java and I'm a little bit confused about a specific issue when I define a thread with an anonymous class (proper use of parenthesis in the constructor definition). The regular declaration…
-1
votes
1 answer

Using a foreach loop to access threads in a list of threads

I am trying to iterate over threads in a foreach loop, but I get an error: Type mismatch: cannot convert from element type Object to Thread The loop is in private static void waitForThreads(List threads) import java.util.*; public class…
-1
votes
1 answer

Print numbers in sequence using threads and lambdas in Java 8

I came across code to print numbers in sequence using two threads in Java. Here's the code public class ThreadPrint { public static boolean isOdd = false; public static void main(String[] args) throws InterruptedException { Runnable…
-1
votes
2 answers

synchronize within a static method - Is this a class level lock?

public static void getResult(HttpSession session) { synchronized(session) { .... } } Here synchronized block is on session, but the method is a static one. Does this result in a class level locking?
programmer
  • 249
  • 4
  • 12
-1
votes
1 answer

invalid column identifier while writing dataframe to oracle

Caused by: java.sql.SQLException: ORA-00904: "XXXX": invalid identifier at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) at…
-1
votes
1 answer

process.waitFor(timeout, timeUnit) does not quit the process after specified time

I'm trying to execute a visual basic script code in my java application using process builder. As script provided by the user might not finish its execution in time, I want to provide means to limit this execution time. In the following code, you…
Ahmet Eroğlu
  • 594
  • 1
  • 7
  • 23
-1
votes
2 answers

Java multiple thread join issue

So i need to process a couple data files using threads (already splitted), and i'm having issues on how to stop the main thread till all the subthreads finish. i looked around and tried to use join() but this causes an issue: If i join the main…
-1
votes
1 answer

ConcurrentHashMap Values not updating

I am trying to create a simple multithreaded dictionary/index using a group of Documents which contain words. The dictionary is stored in a ConcurrentHashMap with String keys and Vector values. For each word in the dictionary there is an appearance…
-1
votes
1 answer

How to build a very simple multithreaded pipeline in Java?

I am trying to run some filters on a matrix within a multithreaded pipeline to save some time. Sadly, there are appearent synchronization issues which I fail to fully grasp yet. What I'm expecting is that I can input a matrix to my step() function…
fortuneNext
  • 109
  • 1
  • 14
-1
votes
1 answer

How do you collect data from all your threads in java?

So I made a class that extends Thread class and I have a main class that calls start(). I have created 1000 threads to run my program in this way: int ThreadNum = 1000; for(int i=0; i
-1
votes
1 answer

Java: thread able to call a method that is in synchronised block of some other thread

thread t1 is calling test1() method of Test class object ob. thread t2 is calling test1() method of Test class object ob in synchronized block. t1 is able to call test1() method of ob even though test1() method call of ob is in synchronised block…