I have few asynchronous tasks running and I need to wait until at least one of them is finished (in the future probably I'll need to wait util M out of ... |
I'm looking for the simplest, most straightforward way to implement the following:
- The main program instantiates worker
threads to do a task.
- Only
n tasks can be running at once.
- When
n is reached, no ... |
I have a method that I would like to call. However, I'm looking for a clean, simple way to kill it or force it to return if it is taking ... |
I have some thread-related questions, assuming the following code. Please ignore the possible inefficiency of the code, I'm only interested in the thread part.
//code without thread use
public static int getNextPrime(int ...
|
... the question says it all I believe!
|
This is a poll of sorts about common concurrency problems in Java. An example might be the classic deadlock or race condition or perhaps EDT threading bugs in Swing. ... |
I have an object which does some computation, then for each iteraction I want to draw what happens. While the drawing is happening, I want it to wait.
This is what I ... |
|
I want to implement the usual cooperative mechanism for canceling a thread.
However the java memory model was only fixed in JDK5 while I'm in a pre-JDK5 environment.
I understand, this means that ... |
Is it possible to attach an UncaughtExceptionHandler to a TimerTask? (Other than by calling Thread.setDefaultUncaughtExceptionHandler())
Cheers
Rich
|
Here's a snippet of code that I saw in some code I'm maintaining.
Object lock = new Object();
synchronized( lock )
{
try
{
...
|
I'm looking for a modern java threading book. I've quite enjoyed reading Taming Java Threads by Allen Holub, but it's a little old now. That was 8 years ago.
I want ... |
I'm aiming to learn about concurrency in Java. Currently my state of knowledge is poor. I'm pretty sure I know what "volatile" means. I sort of know what ... |
This blog post demonstrates a way to implement a mutex per string id idiom. The String ids used are to represent HttpSession ids.
- Why do we need to wrap a ...
|
I need your help on the design of the restore-procedure in a backup system I'm building. The prerequisites are the following:
- A restore can be made of one or several files.
- A ...
|
In Brian Goetz's article on how to handle InterruptedException, one paragraph stands out:
The one time it's acceptable to swallow an interrupt is when you know the thread ... |
I want to convert this linear loop into a concurrent one:
for(Item item : ItemList) {
processItem(item);
}
Is this really the shortest way to do this?
class Worker implements Runnable {
...
|
I am at the end of my first year doing computer science and want to mess around with something basic. I want to use threads so I can learn.
What are some ... |
Reading the javadoc on FileDesciptor's .sync() method, it is apparent that sync() is primarily concerned with committing any modified buffers back to the underlying storage. I.e., making sure that anything that ... |
Does anybody know why the method join() member of a java.lang.Thread was named like that? Its javadoc is:
Waits for this thread to die.
When join is called on some thread ... |
I am working on a (database-ish) project, where data is stored in a flat file. For reading/writing I'm using the RandomAccessFile class. Will I gain anything from multithreading, and giving each ... |
I have some problem with CompletionService.
My task: to parse parallely for about 300 html pages, i need to wait for all the results only for 5 seconds, then - return ... |
I will be making multiple HTTP calls concurrently and want to allow the user to selectively cancel certain tasks if they take too long. A typical scenario: 1 task pulls twitter ... |
How do I modify an int atomically and thread-safely in Java?
Atomically increment, test & set, etc...?
|
I'm writing a Java program which uses a lot of CPU because of the nature of what it does. However, lots of it can run in parallel. When I run ... |
So, I'm curious. How do you handle setting maximum execution time for threads? When running in a thread pool?
I have several techniques but, I'm never quite satisfied with them. So, I ... |
Does java.util.concurrent.atomic.AtomicBoolean not have a method that can atomically negate/invert the value? Can I do it another way? Am I missing something?
|
If I have a class that implements the Runnable interface, what are the differences between these statements in the main method?
MyThread t1 = new MyThread();
t1.start();
and
MyThread t2 = new MyThread();
new Thread(t2).start();
|
From javadoc:
- A
ConcurrentLinkedQueue is an appropriate choice when many threads will share access to a common collection. This queue does not permit null elements.
ArrayBlockingQueue is a classic "bounded buffer", in which ... |
I've got a requirement for a list in Java with a fixed capacity but which always allows threads to add items to the start. If it's full it should remove ... |
I need to draw a graph of write accesses of two concurrently running threads. What is the best way to write a timestamp value pair of these accesses to an array, ... |
I need a queue that can be processed by multiple readers.
The readers will dequeue an element and send it to a REST service.
What's important to note are:
- Each reader should be dequeueing ...
|
My question relates to this question asked earlier. In situations where I am using a queue for communication between producer and consumer threads would people generally recommend using LinkedBlockingQueue ... |
Motivation
I want extra eyes to confirm that I am able to call this method XMPPConnection.sendPacket(
Packet ) concurrently. For my current code, I am invoking a List of Callables (max 3) ... |
What is an efficient way for a Java multithreaded application where many threads have to read the exact same file (> 1GB in size) and expose it as an input stream? ... |
I have at my disposal a REST service that accepts a JSON array of image urls, and will return scaled thumbnails.
Problem
I want to batch up image URLs sent by concurrent ... |
I have encountered a problem twice now whereby a producer thread produces N work items, submits them to an ExecutorService and then needs to wait until all N items have been ... |
public class Test extends Thread{
public void hello(String s){
System.out.println(s);
}
public void run(){
...
|
How does the Boost Thread libraries compare against the java.util.concurrent libraries?
Performance is critical and so I would prefer to stay with C++ (although Java is a lot faster these days). Given ... |
I'm new to threads. How can I get t.join to work, whereby the thread calling it waits until t is done executing?
This code would just freeze the program, because the ... |
I have pin pointed a bottle neck in my application, it seems to me that it boils down to a call to Thread::setContextClassLoader.
Basically I was forced to mess around ... |
i'm working with java.nio.channels.Selector and i'd like to create a separate thread for each selectedKey that is ready for read/write/accept but i want to make sure that the same socket is ... |
Consider the following shell script:
gzip -dc in.gz | sed -e 's/@/_at_/g' | gzip -c > out.gz
This has three processes working in parallel to decompress a stream, modify it, and re-compress ... |
I'm new to the package java.util.concurrent. I've created the following program testing if a number is a prime using a multi and a monothreaded strategy.
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class IsPrime
...
|
I'm midway through programming a Java program, and I'm at the stage where I'm debugging far more concurrency issues than I'd like to be dealing with.
I have to ask: how do ... |
I have a Java Thread like the following:
public class MyThread extends Thread {
MyService service;
...
|
I have always been kind of confused by threads, and my class right now makes heavy use of them. We are using java.util.concurrent but I don't even really get the basics. ... |
I have a web application that synchronizes with a central database four times per hour. The process usually takes 2 minutes. I would like to run this process as ... |
I am writing code that will spawn two thread and then wait for them to sync up using the CyclicBarrier class. Problem is that the cyclic barrier isn't working as expected ... |
Experts -
I need some advice in the following scenario.
I have a configuration file with a list of tasks. Each task can have zero, one or more dependencies. I wanted to ... |
I was wondering why threads spontaneously awake from wait() in java.
Is it a design decision? Is it a compromise?
EDIT: (from Java Concurrency in Practice, p. 300)
wait is even allowed ... |
I would like to create comprehensive checklist for Java low latency application. Can you add your checklist here?
Here is my list
1. Make your objects immutable
2. Try to reduce synchronized method
3. Locking ... |
For example I such a code
...
get some memory and lose all the pointers to that memory so that System.gc(); can collect it.
call System.gc();
do some other tasks;
Here does the "do some other ... |
Why do we call the start() method, which in turn calls the run() method?
Can't we directly make a call to run()?
Please give an example where there is a ... |
What does phrase "synchronization with main memory" mean?
|
I have done good amount of Java programming, but yet to master Threading & Concurrency. I would like to become an expert programmer in threading & concurrency. I have also ... |
I need to maintain a list of userids (proxy accounts) which will be dished out to multithreaded clients. Basically the clients will use the userids to perform actions; but for this ... |
I've used Concurrent Pascal, a tool which helps debug concurrent algorithms because when it runs your code, it randomizes which thread to swap to at every possible step, trying out as ... |
I'm currently working on some code for a course. I can't post the code but I'm permitted to talk about some high level concepts that I'm struggling with and receive input ... |
Can we call thread_object.start() from within a constructor of this same object?
Is this approach a good idea ?
|
I'm working with core java and IBM Websphere MQ 6.0. We have a standalone module say DBcomponent that hits the database and fetches a resultset based on the runtime query. The ... |
I am really curious about how does the JVM work with threads !
In my searches in internet, I found some material about RTSJ, but I don't know if it's the right ... |
I plan to use dom4j DOM Document as a static cache in an application where multiples threads can query the document.
Taking into the account that the document itself will never ... |
I have 2 pools of threads
ioThreads = (ThreadPoolExecutor)Executors.newCachedThreadPool();
cpuThreads = (ThreadPoolExecutor)Executors.newFixedThreadPool(numCpus);
I have a simple web crawler that I want to create an iothread, pass it a url, it will then fetch ... |
I have gone through Head First Java and some other sites but I couldn't find complete stuff related to Threads and additional concurrency packages at one place.
Please suggest a book/website which ... |
I have been playing with my own version of this, using 'if', and all seems to be working fine. Of course this will break down horribly if signalAll() is used ... |
The code below is to emulate a robotics simulator I'm working with. I'm not entirely sure why this doesn't work - I'm not very familiar with threads and even though I've ... |
Can someone briefly explain on HOW and WHEN to use a ThreadFactory? An example with and without using ThreadFactory might be really helpful to understand the differences.
Thanks!
|
Many people at SO adviced to dive into Java concurrency by reading Java Concurrency in Practice (JCIP), sometimes Doug Lea's book of 1999 is mentioned as well:
|
I am executing a Callable Object using ExecutorService thread pool. I want to give a name to this thread.
To be more specific, in older version I did this -
Thread thread = ...
|
Suppose I have a instance variable that has original value:
Integer mMyInt = 1;
There are two threads.
The first changes mMyInt by calling:
void setInt() {
mMyInt = 2;
}
The second thread ... |
I am working on a server client application right now (just for learning purposes), and am trying to get information to make a design decision regarding threads in this application.
Currently i ... |
Is while (true) { ... } loop in threads bad? What's the alternative?
Update; what I'm trying to to...
I have ~10,000 threads, each consuming messages from their private queues. I have one ... |
I have an underlying asynchronous out-of-order query/response system that I want to make synchronous. Queries and responses can be mapped by marking the queries with unique IDs that in turn will ... |
I'm trying to write a Java serial device driver and want to use the (new to me) java.util.concurrent package. I have one method which sends a packet then waits for ... |
If I have code like this -
long x;
x = 0xFFFFFFFFL;
If i run this code on a 32 bit machine is it guaranteed to be atomic or is it possible that ... |
I have 2 threads running in paralel. The run function of the threads is as follows
public void run(){
Runtime rt = Runtime.getRuntime();
Process s;
...
|
/*
This should always produce 0 as output since all three methods increment(), decrement(), value() are thread safe(synchronized). but it is returning 1
*/
class Counter implements Runnable {
...
|
What is the difference between memory consistency errors and thread interference?
How does the use of synchronization to avoid them differ or not? Please illustrate with an example. I couldn't get this ... |
OK I am not only new to concurrency in java but am also fairly new to java programming. I tried understanding concurrency from The java tutorials, tried reading Concurrency in ... |
Please help me understand this program's execution and what concepts apply here in the larger sense? An illustration which explains thread(s)/stack(s) creations and destruction would be helpful.
class Joining {
...
|
I have built a java application and have a thread thats doing something in the background when a button was pressed. The problem is, that thread might lock up, perhaps due ... |
Say I spawn a thread every couple seconds using the method below and every thread takes about a second to complete. Do the finished threads get deleted?
new Thread (new myRunnableClass()).start();
|
I have a bit of a problem. I have a java application and when it starts it needs to make around six maybe seven threads that just wait for some sort ... |
otherThread.join( time ) appears to wait time in real milliseconds. I want to wait time in actual CPU time so that I can get consistent behavior within my application.
I've done ...
|
I've been spending a great deal of time trying to understand this. I created a JApplet that used Thread.sleep() in a loop to animate the applet. But when I ... |
JUnit @Tests have the useful ability to specify a timeout argument so that a poorly written program gets killed automatically if it takes longer than timeout seconds. The problem is this ... |
I'd like to have my thread (the main/EDT) wait until changes to a file occur and then wait. DefaultFileMonitor extends Runnable and hence runs in a thread of its own. Here ... |
I have this method to write messages to a socket:
public void sendMessage(byte[] msgB) {
try {
synchronized (writeLock) {
...
|
Out of the below two synchronization strategy, which one is optimized (as in processing and generated byte code) and also the scenario in which one should use one of them.
public synchronized ...
|
I've been ask to build a multithreaded java application using the java.util.concurrent. I'm not familiar with this library, but have a good understanding of problems with multi-threaded code.
I'm looking for tutorial ... |
Possible Duplicate:
Java: “implements Runnable” vs. “extends Thread”
Should I use Runnable interface or extends from Thread class? Is there any advantage on one and another?
Thanks ... |
Future.get(timeout) does not reliably throw the TimeoutException after the given timeout. Is this normal behavior or can I do something to make this more reliable? This test fails on my machine. ... |
For debugging purposes, I want to figure out which threads of my program are still running. There's seems to be one or more threads that accidentally were not interrupted. Some sort ... |
Could someone point me to snippet for making parallel web-requests? I need to make 6 web requests and concatenate the HTML result.
Is there a quick way to accomplish this or do ... |
What is a good book for learning the basics of concurrency? I've never programmed in a multithreaded environment, so it should assume no prior experience in writing multithreaded programs whatsoever. Should ... |
I got a class that I use as a table.
This class got an array of 16 row classes.
These row classes all have 6 double variables.
The values of these rows are set ... |
Greetings Overflowers,
- The data structure is an acyclic tree
of arbitrary number of nodes.
- Shallower nodes are dependent on the
results of deeper nodes.
- The final result can simply be
calculated by traversing the tree
recursively.
- If I had ...
|
I have a multi-threaded Java program with a bunch of rules around threading: For example, code in class A should only be called from the UI thread; 3 ... |
I have an array of size N. I want to shuffle its elements in 2 threads (or more). Each thread should work with it's own part of the array.
Lets say, the ... |
Below is implementation of QuickSort by using interface, I need some tips how I can implement by using threading/concurrency.
i. Write one of the sort() methods so that it provides an
implementation that ... |