Tagged Questions
0
votes
0answers
13 views
Stop thread using volatile
I'm facing a problem with stopping some threads I'm creating.
The code
private volatile int status = STOPPED;
@Override
public void run() {
logger.info("Thread with ID : " + id);
status = ...
0
votes
3answers
39 views
How to stop a thread as soon as a certain amount of time expires?
I am having a problem trying to stop a thread instantly after a certain amount of time has elapsed, because thread.stop and similar others have been depreciated.
The thread that I am trying to stop ...
0
votes
0answers
12 views
trying to move an image on either direction and make string appear in swirly colors .Its not working using threads
Here is my code..have used multithreading concept in applet graphics im trying to ove the image in either direction and make the string appear in swirly colors.Its working in seperate ...
1
vote
1answer
12 views
Interrupt ThreadPoolExecutor current threads and empty its queue
I am currently working on an application that has in its main layout a ListView, its items are wrappers for real files contained in a directory.
When the list is populated I execute an AsyncTask that ...
-1
votes
0answers
16 views
java managing memory with multiple threads
I am using a tomcat servlet that concurrently stores content as it becomes available to the servlet. A single request may have 1 or several thousand pieces (components) that may need to be stored.
To ...
0
votes
0answers
20 views
Android - Sending Message to Thread Incoming Handler
I have a Service that starts a new Thread that handles network activity. I have my Activity, Service, and Thread all in separate files. I am trying to set up communication between them using a ...
0
votes
1answer
28 views
How to write Java code that is synchronized on an instance of an entity
I'm using Hibernate and Spring and I want to write Service code to cater for the scenario where, in two separate threads, a DAO is used to fetch an entity instance by id, and it is the same id / ...
0
votes
2answers
29 views
Asynchronous processing with a single thread
Even after reading http://krondo.com/?p=1209 or Does an asynchronous call always create/call a new thread? I am still confused about how to provide asynchronous calls on an inherently single-threaded ...
3
votes
3answers
44 views
Super keyword in java and multithreading
I am a newbie to the world of Java.
While studying Multithreading I came across this program :-
class Shared
{
int x;
synchronized void show(String s,int a)
{
x=a;
System.out.println("Starting ...
1
vote
0answers
20 views
Is LIBSVM thread safe
I would like to take advantage of today's CPU mutli-core capabilities when using LIBSVM. What I'd like to know/understand is whether I can safely call LIBSVM services from multiple threads ...
0
votes
1answer
85 views
executing millions of thread concurrently in java
I have a requirement to handle millions of thread and i know its quite dependent on the hardware configuration and jvm.
I have used executors for the task
call flow of my project :
...
0
votes
0answers
12 views
FileObserver thread created but no changes monitored
I have a Service which starts a thread based on a condition. In that thread, I create a FileObserver for monitoring CREATE or MODIFY changes in a file. Although the FileObserver thread is created and ...
0
votes
0answers
12 views
Analyze stand alone Java Application locally for threads
Respected Experts,
I have a stand alone java application and want to monitor the threads created by it. I am planning to use a tool like JConsole or JVisualVM. However, I am not able to connect these ...
2
votes
1answer
27 views
Java profiler to resolve performance issues
Can any one suggest me the Java profiler to identify Threading issues and performance issues in the Java Project.
Thanks!
0
votes
2answers
44 views
How to correctly judge the performance in Java using a profiler?
I hava a Java project in which I am using threading, but performance of my project is not good and its running very slow on different machines.I want to improve the performance. I used VisualVM ...
0
votes
1answer
16 views
How to propagate timeout from one FutureTask to another dependent one used by its Callable?
I am in the following situation (perhaps I have overengineered the whole thing or I am in a complete deadlock, but cannot think to another way of doing that):
Take one or more FutureTask that ...
0
votes
0answers
24 views
Which Database is best for desktop application where multiple threads trying to write into db?
I am new to java desktop application development
Problem Description -
I am currently developing one desktop application in java (with netbeans) in which multiple threads are trying to write into ...
0
votes
0answers
30 views
SwingWorker issue: doInBackground() exits without calling process()
I am trying to call a lengthy process when the start button on the GUI is clicked. I have tried to implement Swing Worker and it works fine. The problem I have is: doInBackground() calls the method ...
0
votes
1answer
14 views
Queries an http request on server side dilemma
I am building my server side for an app and I am thinking if I should run each query or http request (or any other time consuming process) on a thread (java)?
What will happen if new process will ...
-1
votes
2answers
42 views
having static variable for both class and thread
I'm working on saving images in a class. I've created a thread, which will download the image and save it. But I need the imagepath from the thread. So I thought of creating a static Hashmap since the ...
0
votes
2answers
35 views
Search completes in specific time
I have a code to to search files in specific location. I want to add time bound to stop search . If I say search in 5000 ms, then search has to stop after 5000ms and display the results.
Can anyone ...
0
votes
0answers
15 views
How to run background thread only once using the ScheduledExectuors?
Below is my Interface -
public interface IClient {
public String read(ClientInput input);
}
This is my Implementation of the Interface -
public class TempClient implements IClient {
...
1
vote
1answer
30 views
Return result from asynchronous SQL query (Java)
I am using MySQL to store data for a game I am making and need to access the database from outside the main thread so to not interupt it from a long query and return the data to the main thread to be ...
2
votes
2answers
34 views
Java chat application using Swing (Conceptual)
I want to write a chat application in Java using Swing as an interface. There are several tutorials about this, but most are very specific and leave me confused. I'm especially unsure about how to ...
0
votes
2answers
44 views
for Java, is Class.newInstance() thread safe
a part of code like this:
class Test {
private static final Map<String, Class> urlHandlers = new ConcurrentHashMap<String, Class>();
static {
urlHandlers.put(urlRegexA, ...
0
votes
2answers
13 views
How to keep a Bluetooth connection alive across multiple activities?
I cannot find an answer to my specific problem anywhere.
I need a way to have my application activities be able to all separately exchang data with a Bluetooth connection. Here's what I am trying to ...
1
vote
1answer
80 views
Out of Thin Air Safety
Java Concurrency in Practice explains this concept:
When a thread reads a variable without synchronization, it may see a
stale value, but at least it sees a value that was actually placed
...
2
votes
2answers
22 views
How to use RestTemplate efficiently in Multithreaded environment?
I am working on a project in which I need to make a HTTP URL call to my server which is running Restful Service which returns back the response as a JSON String.
Below is my main code which is using ...
4
votes
1answer
61 views
How to make Java threads to get fair amount of CPU time
I am new to Java. I have searched this site before posting this question. Please forgive me if my question looks stupid.
The have given below the code for which I am looking for answer.
My intention ...
1
vote
2answers
38 views
How to improve the performance while using ExecutorService with thread timeout capabilities?
I am not a Multithreading Expert but I am seeing some performance issues with my current code which is using ExecutorService.
I am working on a project in which I need to make a HTTP URL call to my ...
0
votes
0answers
8 views
ProgressMonitorInputStream will not update in SwingWorker
I am trying to make a simple utility from my GUI applications that fetches data from websites. One of the websites, in particular, has a very loading time. So I decided it would best to use ...
2
votes
2answers
66 views
SwingWorker, Cancel-Button doesn't work
I have a window, with a Start- and Stop-Button. The Start-Button starts the algorithm and the stop-button should stop it. I use SwingWorker do run the algorithm in the background and normally calling ...
1
vote
1answer
31 views
ExecutorFramework is adding up lot of time in performance test?
I am working on a project in which I am trying to make a URL call to one of my server using RestTemplate which gives me back a JSON String as a response and it is working fine...
Now I decided to do ...
3
votes
2answers
56 views
Performance/Time issue in different machines due to threading in Java [on hold]
I am using Threading in my Java project. When I am running my project on my Machine than it takes more time (approx 30min) in comparison to other Machine. Both Machines have same 64bit configuration ...
0
votes
3answers
56 views
How to Stop Multiple Instances of a Thread Class one by one?
I have a Thread worker class Java, which is initiated several times (Lets say 10 instances). Now I want to stop these running threads one by one in the order they a created (First in first). All these ...
0
votes
2answers
57 views
Java - Get thread state
I am using ThreadPoolExecutor to run the threads.
ExecutorService executorService = Executors.newCachedThreadPool();
Future<?> future = executorService.submit(new MyRunnable());
Based on ...
0
votes
0answers
19 views
set the volume of two simultaneously playing threads of mediaplayer
I am playing two threads of mediaplayer objects simultaneously and the problem is that how do I set the volume for both the threads that when the seekbar's progress is moved to left then the volume of ...
1
vote
2answers
34 views
What happens to stdin data when multiple threads are using Scanners on System.in in Java?
Say I have a main program that listens for command line arguments on stdin. This main program spawns a thread to do some stuff, and the thread also needs to listen to stdin.
If two different threads ...
-2
votes
2answers
49 views
How can i dynamically count the elements in a ArrayList?
I have a class Concept with a ArrayList and another class that adds Concepts to the ArrayList of the Concept class, based on what Concepts are already there.
class Concept{
...
1
vote
3answers
64 views
Map of AtomicInteger
I want to implement a shared object for calculation of statistics of executions of operations.
Objects state will be represented by Map<String,AtomicInteger>(key is the name of operation, value ...
0
votes
1answer
31 views
Waiting for a thread, to complete execution or max time elacpses, which ever comes first
So the title is explanatory, I want to wait on a thread for a max time say 1 sec, now within this 1 sec if the other thread receives a response then its fine, otherwise after 1 sec whether or not a ...
0
votes
1answer
29 views
Spawn multiple threads that take inputs from single collection and put results in single collection
Here is a brief of what i want to do , I have a scenario where
number of text files are generated dynamically on daily basis. 0
to 8 per day. size of each file can be small to big. depending on
...
1
vote
1answer
29 views
Thread safe data management in Android to keep UI thread free
To keep the UI unblocked Android does not recommend doing a lot of calculations on the UI thread. Is there a way then to be able to keep data objects in memory without causing contention, i.e. no ...
0
votes
2answers
35 views
Java 7 Multithread Fork Join Scheduler
I wrote a multithreaded program using Java fork/join framework in jre 1.7. This program aims to find certain points which satisfy specified condition in all nodes of a Quadtree(each leaf node in the ...
2
votes
2answers
67 views
How to make method thread-safe
Let's say I have following method
public static String addStringItems(String[] items, boolean forceUpperCase) {
StringBuilder builder = new StringBuilder(items.length);
for (String item : ...
0
votes
1answer
49 views
Java threads notify() wait() for faster calculation
I must create simple application with threads. Task: faster calculation than serial processing. I must use methods notify() or notifyAll(), wait(), interrupt() and operator synchronized.
I tried ...
0
votes
0answers
33 views
getting error with google-guava library while making asynchronous call to a long running thread
I have to implement a method which will return a ListenableFuture<> with a given scenario.
1.there is a method named execute() which will return a listenablefuture<transformresult> ...
-1
votes
2answers
40 views
How synchronization of threads work along with Sleep()?
class ABC extends Thread
{
public void run()
{
display();
}
public synchronized void display()
{
{
System.out.println("1");
...
36
votes
9answers
33k views
How do I optimize for multi-core and multi-CPU computers in Java?
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 it, it only seems to use one CPU until it needs more then ...
23
votes
6answers
5k views
Can anyone explain thread monitors and wait?
Someone at work just asked for the reasoning behind having to wrap a wait inside a synchronized.
Honestly I can't see the reasoning. I understand what the javadocs say--that the thread needs to be ...