multithreading

Improve downloading speed in subthread

I have a program which manages serveral subthreads for FTP downloading.It works fine except that the downloading speed becomes slow when number of subthreads increased.I've tried downloading the same resource with IE at the same time,and it's much faster.So how can I improve this?All the threads are started by AfxBeginThread.Help would b...

Weird problem using JUnit in multi-thread environment

Hi all, I meet a weired problem when using JUnit in multi-thread environment. The following code should fail, but it actually pass in eclipse. public class ExampleTest extends TestCase { private ExecutorService executor = Executors.newFixedThreadPool(10); private volatile boolean isDone = false; public void test() throw...

how to override thread.start() method in java?

I need to implement thread.start() method in my java code. Please let me know through an example of overriding of thread.start() method and how it works? ...

java.util.concurrent: Should I synchronize to avoid visiblity issues among threads?

I wonder if when using any of the java.util.concurrent classes I still need to synchronize access on the instance so to avoid visibility issues. In short the question is: When using an instance of java.util.concurrent, is it possible that one thread modify the instance (i.e., put an element in a concurrent hashmap) and a subsequent th...

Stop transaction in a thread

I use a TransactionScope in a thread to dump data in my SQL Server database. using (TransactionScope scope = new TransactionScope()) { // Dump data in database scope.Complete(); } The transaction is a long transaction (40 secondes) because data are bigs : that's normal. When I do an Abort() to stop the thread during this tran...

.NET Threading - HttpWebRequest BeginGetResponse + AutoResetEvent

Hi, I would like to know which approach among the two is a better implementation ? I need to create a web request which can range between 200ms to 5 seconds. I need the html response to proceed - so need to block on the main thread. First Approach string GetResponse() { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Crea...

How do I update a JTable based on a notification received from a long-running task in other thread?

I've an Observer TableModel which listens to some changes, performed in the database, and when so the update method below is called. My problem is, how should I prevent errors like: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 at java.util.ArrayList.RangeCheck(ArrayList.java:547) at java.util.ArrayList.set(ArrayList.java:337) ...

how can i remove item from Qtreeview?

basically i want to remove item from Qtreeview on the dropEvent(QDropEvent *event) inherited in a qtreeview subclass. what is the best way to do this? ...

overriding thread.start() method().

try{ private synchronized void start() { if (threadStatus != 0) throw new IllegalThreadStateException(); group.add(this); start0(); if (stopBeforeStart) { stop0(throwableFromStop); } this.run(); } } catch( Exception e ) { System.out.println(e); //this code is giving error (start is not...

How to interrupt python multithreaded app?

I'm trying to run the following code (it i simplified a bit): def RunTests(self): from threading import Thread import signal global keep_running keep_running = True signal.signal( signal.SIGINT, stop_running ) for i in range(0, NumThreads): thread = Thread(target = foo) ...

Displaying images with a high frame rate

Hi, here's the problem: I have a custom hardware device and I have to grab images from it in C#/WPF and display them in a window, all with 120+ FPS. The problem is that there is no event to indicate the images are ready, but I have to constantly poll the device and check whether there are any new images and then download them. There a...

Giving my Python application a web interface to monitor it, using Tornado

I've got a Python application which is daemonized and running on a server 24/7. I'd like to be able to give an incredibly simple web interface so that I can monitor the changing values of a few variables within the program. I'm using Tornado, and I'm up and running with the simple 'Hello, world' that you can find on the Tornado homepag...

Python How to share a serial port with two different threads (Class A, Class B)

Hello guys, thank your for reading. Well, I have a single python process which is using a serial port (unique resource) which is manage using an instance of a (A=Class A). Exist two different thread initialized using B=Class_B() and C=Class_C(), which are constantly using the serial port resource through the objected already created cal...

Create NSWindow from worker thread crash?

The Thread Safety Summary on developer.apple.com states that NSWindow's are thread safe* and can be created from worker threads. I have a worker thread that i've created rather simply: [NSThread detachNewThreadSelector:@selector(threadProc:) toTarget:self withObject:nil]; that tri...

Is the List<T>.AddRange() thread safe?

Can I, without locking, safely call List.AddRange(r) from multiple threads? If not, what sort of trouble would I run into? ...

Gas Station Simulation: How to simulate Cars coming at random intervals?

The assignment is as follows: The gas station consists of 2 pumps. Each pump has a certain amount of fuel it can distribute. Cars arrive at random intervals and attempt to use one of two pumps: - If a pump is available and has fuel, the car is immediately allowed to use it. Each car requires a certain amount of fuel (random numbe...

How to sort an array of M numbers using N threads in java?

I have to use N(i=1..N) threads to sort an array of M numbers,each thread start to sort the array from position (N*i)%m. Could anyone help me? ...

python - how to get the numebr of active threads started by specific class ?

code looks like below: class workers1(Thread): ... def __init__(self): ... Thread.__init__(self) ... def run(self): ... ...do some stuff class workers2(Thread): ... def __init__(self): ... Thread.__init__(self) ... def run(self): ... ...do some stuff if __name__ == "__main__": ... start workers while ...

When implement a thread safe queue or list does it required to lock before returning Count?

Hi; When implementing a thread safe list or queue; does it requaired to lock on List.Count property before returning the Count i.e: //... public int Count { lock (_syncObject) { return _list.Count; } } //... is it nessesary to do a lock because of the original _list.Count variable maybe not a volatile variable? T...

How to interrupt an IO bound thread.

I am opening a System.Diagnostic.Process to read the stdout from a process and I would like to be able to interrupt it after a certain elapsed time. try { output = outputStream.ReadToEnd(); } catch (ThreadInterruptedException e) { return; } That doesn't work since the thread is in the ReadToEnd() method. I attempted to close t...