Tagged Questions
0
votes
0answers
22 views
Temporary threads leaking things they reference (target java.lang.thread)
I have an android app with a non-UI thread that needs to be responsive, but which needs to occasionally perform a long running task. To do this, I make it spawn a thread to run the task. This thread ...
0
votes
2answers
48 views
Speed java code by moving function to a thread of its own
The following code in the far bottom becomes slow when calling `Moon m = new Moon();.
to fix this I would like to put the following code in a thread or something so that the moonCalTimer exits ...
2
votes
3answers
26 views
javac goes crazy on CPU utilization ECJ is able to maintain a predictable CPU utilization for a multi-threaded Producer -Consumer
I was running a 1 Producer thread, 1 Consumer thread problem with a shared buffer and a temporary cache (of 1000 elements).
The eclipse execution (ECJ) utilizes 33% CPU (1 core for producer, 1 for ...
0
votes
0answers
34 views
file handling and threads
I am trying to read three files using thread and then pass on the content to the writer class to write it to another file. The thread associated with the first file(which has line break in it) is ...
0
votes
2answers
33 views
Producer Consumer program using multithreading
I am trying to implement standard Producer Consumer problem using java.
I done some code to do it.
Here is the code:
Producer Class:
class Producer implements Runnable
{
public Producer()
{
...
0
votes
4answers
49 views
How to make two threads work in same time
I make two threads: one for fill an array and the second one print it. It seems like the two thread don't work in same time.
When i run the code its print first thread working then its print the ...
0
votes
2answers
59 views
Infinite loop stops app from responding. What to do?
I have written a small app that draws a circle on a surfaceview that is proportional to the amount of sound reaching the phones mic (the louder the sound the bigger the circle).
Everything is working ...
4
votes
3answers
56 views
Observer pattern with threads
I want to run several threads and join them at the end of my main method, so I can know when they have finished and process some info.
I don't want to put my threads in an array and do a join() one ...
0
votes
4answers
45 views
Creating another thread in order to keep track of the application data
I'm looking to create another thread in order to keep track of the game time in terms of seconds. The thread here is at 10ms in order for the animation to move smoothly but because the game time isn't ...
-1
votes
1answer
19 views
IllegalMonitorStateException - wait [on hold]
I have this code :
public static void main(String[] args) throws InterruptedException {
Object obj = new Object();
obj.wait();
obj.notify();
}
please I didn't understand why it ...
0
votes
0answers
23 views
JAVA-MySQL Multi-threaded Application design [on hold]
I am trying to design a multi-threaded application in java. The application takes data from a MySQL database and processes it. Like with all parallel applications, there is synchronization problems ...
1
vote
3answers
42 views
Program does not terminate immediately when all ExecutorService tasks are done
I put a bunch of runnable objects into an ExecutorService:
// simplified content of main method
ExecutorService threadPool = Executors.newCachedThreadPool();
for(int i = 0; i < workerCount; i++) {
...
0
votes
1answer
33 views
Select a thread in threadpool to shutdown
I currently have a threadpool with 2 fixed threads and each thread creates 2 more threads that perform task. I have it set up to where I can pass commands to stop a thread if needed.
What I'm asking ...
1
vote
1answer
44 views
Stoping all threads in ThreadPool if an exception occurs
I need to stop executing threads in a ThreadPool in case any of them throws an Exception.
My solution is one by referencing the ExecutorService on each Runnable and calling shutdownNow() on it. Not ...
1
vote
2answers
48 views
Android send data from main UI thread to another thread
I need to send some data from the main thread to another thread. I've already read a lot of materials on threads, asynctasks and handlers but maybe they created some confusion to me. I read that I ...
0
votes
3answers
65 views
Java multithreading confusing code snippet
How should the code below perform if executed randomly at different time?
public class Unstoppable extends Thread {
private int counter;
@Override
public void run() {
...
0
votes
2answers
45 views
Updating the UI automaticly
I'm working on a Android program that gets his sensor data from a seperate class ( the data i print out in the onSensorChange method and looks fine). No i want to update my UI with the data i have ...
0
votes
0answers
21 views
Undefined function 'javaaddpath' for input arguments of type 'cell'
I am currently call Matlab object in my java code .
The code of matlab is easy like this
function idx = clustering(W, k)
degs = sum(W, 2);
D = sparse(1:size(W, 1), 1:size(W, 2), degs);
...
0
votes
0answers
38 views
Asynchronous communication in android
Can we persist objects using AsyncTask & pass to UI or another class for further use?
for example
public class NetworkConnect extends AsyncTask<String, Void, String>{
@Override
...
0
votes
4answers
47 views
why i cannot send android intent from within new thread?
private void Foo() {
// progressDialog = ProgressDialog.show(this, "", "Loading...");
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Intent ...
0
votes
2answers
33 views
Async process in Spring
I have the following in my Controller
@RequestMapping("/")
@ResponseBody
public String index() {
System.out.println("Parent: " + Thread.currentThread().getName());
task();
return "Hello";
...
-3
votes
2answers
61 views
Exception in thread creating new exceptions [on hold]
I have create my own exception in java and when i use it the console give me this error
Exception in thread "main" Miexcept
at Pelicula.cambiarNombre(Pelicula.java:108)
at ...
0
votes
4answers
46 views
java multithreading for synchronization between tasks
I have a requirement in multi-threaded environment in java. The problem is like;
I have suppose 10 different task, and I want to assign all these 10 task to 10 different threads. Now the finish time ...
0
votes
1answer
22 views
Does scheduleAtFixedRate call a different thread of execution when the current execution is not complete?
I am using timer class to poll my database continuously and after that will do long operation whether scheduleAtFixedRate will create new thread of execution if the current processor is not completed ...
0
votes
2answers
32 views
Is there any mechanism in Python to control the maximum of multi thread?
I'd like to have something like Executors.newFixedThreadPool(3) which is in Java.
That is to say, I want my python program to fork at most 3 multi thread at a time, if the number of multi thread is ...
0
votes
1answer
30 views
Multithreading with TCP / IP socket
I am working on sockets in Java. The thing is we are acquiring signal from hardware device and if the device is not scanned after certain interval (200ms) is hangs. So I need to speed up this ...
-1
votes
2answers
29 views
What race conditions and consequences will it be if thread-unsafe collection is used [on hold]
I have a general question that I cannot quite understand.
What race conditions and consequences will it be if thread-unsafe collection is used?
For example, java.util.HashSet is not thread safe. So ...
0
votes
1answer
22 views
Synchronizing three steps in three different threads?
In my main programme, i start three threads as described below
Thread 1:- having steps 1A and 1B
Thread 2:- having steps 2A and 2B
Thread 3:- having steps 3A and 3B
I want Thread 1, 2 and 3 ...
0
votes
3answers
29 views
Let threads read shared variable until modified
I have a simple class which doesn't require a thread to obtain a lock while reading from my shared object. However if any particular thread tries to modify this shared object, then no thread can read ...
0
votes
0answers
27 views
Why would a Java function block on the monitor of Reference$Lock?
I'm looking into a program that hits some sort of concurrency bottleneck when it goes from 4 to 8 threads. Using Yourkit, I've watched the monitor profile, and it tells me that the threads are ending ...
0
votes
2answers
32 views
How should I properly block access from other threads to this object?
I'm doing this little exercise myself trying to understand how should I work with concurrency and threads.
It happens that sometimes I have an object that I can't modify its source code and that is ...
-3
votes
1answer
107 views
Differences between C++11, C# and Java memory models [on hold]
I know that C++11 memory model was inspired from Java memory model, but there has to be something that differentiates both these memory models.
Java uses synchronize and mutexes
C++11 uses atomics ...
1
vote
1answer
63 views
Android simple draw
Why it doesn't work ? I'm trying to "paint" where i put my finger, to write something. For example, when i am trying to make a C he looks like this: http://postimg.org/image/5obyif4o1/ ...
2
votes
2answers
46 views
Notification in thread
Will the thread give up the monitor immediately as soon as the notify() method is invoked like as it happens in wait(). Or when the notify() is invoked, will the monitor be released after the ...
-2
votes
2answers
39 views
Is it advisable to call my method in a Thread object while it executes another method?
A thread consists of two methods namely method A(always listen to the socket and read data from it) and method B(close socket connection).
Method B is a synchronised method. Is it a good way of ...
0
votes
3answers
59 views
Java - Is this way of designing acceptable? [on hold]
Well, I'm doing a mini-project on Employee Management System. In my project, there is a base class named Person and another class Employee(which inherits Person). Now, I want to create a new class ...
0
votes
1answer
33 views
Code doesn't work unless I include a println or breakpoint
I'm making a rudimentary multiplayer shooter as part of a university course on computer graphics.
For client->server communication I'm using UDP. Each client has a ClientController thread, which ...
0
votes
2answers
64 views
Testing threaded code java
I'm working on testing a certain class that utilises a WatchService. This class has a method, processEvents, that works something like this (from ...
0
votes
3answers
23 views
when thread calls wait it releases the lock versus race condition
According to the basic definition of synchronized method from source - link
"When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for ...
0
votes
2answers
23 views
Starvation prevention and ReentrantLock(true);
If I have a monitor with the following structure
if( [condition lock condition])
{
do{
cond.lock()
}while([condition lock condition]);
}
Will ReentrantLock(true) prevent any ...
0
votes
1answer
28 views
Call JavaFX application twice
would need to help me with the following, I am implementing an application in javafx, this applicatio I call through a click on a button.
the problem is that when I close the application and I can not ...
0
votes
3answers
37 views
BlockingQueue: how can multiple procucers stop a single consumer?
I wrote a producer/consumer based program using Java's BlockingQueue. I'm trying to find a way to stop the consumer if all producers are done. There are multiple producers, but only one consumer.
I ...
4
votes
5answers
113 views
Thread safety in huge data model
Background:
I have got a (more or less) huge data model in the memory. The model contains around 3.150.000 to 12.600.000 objects that could be modified directly. In addition, there are around ...
0
votes
1answer
52 views
Synchronization of map object
I have a Map object which corresponds to a key value pair stored in a File.
private static Map myMap;
There is a manager class for this Map object which has a method getMap() which returns the ...
0
votes
2answers
62 views
Run single threaded Java program on multiple threads [on hold]
For school I was assigned to write a program that simulates a game of craps. It works great on one thread, but I want to know how much work it would be to make it run on all the CPU cores.
Currently ...
-2
votes
1answer
15 views
Java newFixedThreadpool keeps the first n threads suspended
I'm using Executors.newFixedThreadPool(N) where N is any number representing a pool capacity.
The problem is the following: Say we have 100 threads and N=10. All the Runnables are propagated to the ...
-2
votes
0answers
26 views
Thread safety error. Tried to use synchronized keyword but it doesn't work [on hold]
I am having a class HelloWorld with a method public static Boolean[] exampleMethod(no of employee array ){...}
when this method is called by two users simultaneously it result into wrong result. ...
0
votes
0answers
17 views
Android - app causing trouble using Sockets in release mode
I have 2 buttons, Server and Client.
The server button contain a textview which prints stuff received from the client.
The client button open Editbox and Send button which uses OnClick function.
In ...
2
votes
1answer
84 views
Run listener when task returns
I have:
An ExecutorService that someone else has provided.
A Runnable task that cleans up after itself when it is interrupted.
A Runnable listener
My job is to run the task on the ExecutorService ...
1
vote
7answers
69 views
Multiple threads access the same file
I have two functions which are dealing with the same file:
public MyShelf(){
…
//Change the content of note.txt file
public synchronized void updateFile(){
File file = ...