Search Results

Search found 3641 results on 146 pages for 'threads'.

Page 17/146 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • Implementing java FixedTreadPool status listener

    - by InsertNickHere
    Hi there, it's about an application which is supposed to process (VAD, Loudness, Clipping) a lot of soundfiles (e.g. 100k). At this time, I create as many worker threads (callables) as I can put into memory, and then run all with a threadPool.invokeAll(), write results to file system, unload processed files and continue at step 1. Due to the fact it's an app with a GUI, i don't want to user to feel like the app "is not responding" while processing all soundfiles. (which it does at this time cause invokeAll is blocking). Im not sure what is a "good" way to fix this. It shall not be possible for the user to do other things while processing, but I'd like to show a progress bar like "10 of 100000 soundfiles are done". So how do I get there? Do I have to create a "watcher thread", so that every worker hold a callback on it? I'm quite new to multi threading, and don't get the idea of such a mechanisem.. If you need to know: I'm using SWT/JFace. Regards, InsertNickHere

    Read the article

  • How can I remove a JPanel from a JFrame?

    - by Roman
    Recently I asked here how to add a new JPanel to JFrame. The answer helped me to get a working code. But not I have a related question: "How can I remove an old JPanel". I need that because of the following problem. A new JPanel appears appears when I want (either time limit is exceeded or user press the "Submit" button). But in several seconds some element of the old JPanel appears together with the component of the new JPanel. I do not understand why it happens. I thought that it is because I have to other threads which update the window. But the first thread just add the old panel once (so, it should be finished). And in the second thread I have a loop which is broken (so, it also should be finished). Here is my code: private Thread controller = new Thread() { public void run() { // First we set the initial pane (for the selection of partner). SwingUtilities.invokeLater(new Runnable() { public void run() { frame.getContentPane().add(generatePartnerSelectionPanel()); frame.invalidate(); frame.validate(); } }); // Update the pane for the selection of the parnter. for (int i=40; i>0; i=i-1) { final int sec = i; SwingUtilities.invokeLater(new Runnable() { public void run() { timeLeftLabel.setText(sec + " seconds left."); } }); try {Thread.sleep(1000);} catch (InterruptedException e) {} if (partnerSubmitted) {break;} } // For the given user the selection phase is finished (either the time is over or form was submitted). SwingUtilities.invokeLater(new Runnable() { public void run() { frame.getContentPane().add(generateWaitForGamePanel()); frame.invalidate(); frame.validate(); } }); } };

    Read the article

  • Stopping work from one thread using another thread

    - by 113483626144458436514
    Not sure if my title is worded well, but whatever :) I have two threads: the main thread with the work that needs to be done, and a worker thread that contains a form with a progress bar and a cancel button. In normal code, it would be the other way around, but I can't do that in this case. When the user clicks the cancel button, a prompt is displayed asking if he wants to really cancel the work. The problem is that work continues on the main thread. I can get the main thread to stop work and such, but I would like for it to stop doing work when he clicks "Yes" on the prompt. Example: // Main thread work starts here t1 = new Thread(new ThreadStart(progressForm_Start)); t1.Start(); // Working for (i = 0; i <= 10000; i++) { semaphore.WaitOne(); if (pBar.Running) bgworker_ProgressChanged(i); semaphore.Release(); if (pBar.IsCancelled) break; } t1.Abort(); // Main thread work ends here // Start progress bar form in another thread void progressForm_Start() { pBar.Status("Starting"); pBar.ShowDialog(); } I could theoretically include a prompt in the cancelWatch() function, but then I would have to do that everywhere I'm implementing this class.

    Read the article

  • How to use HttpContext.Current on asynchronous threads?

    - by Eran Betzalel
    I've a schedule tasks mechanism (very similar to DotNetNuke's) in my business logic library (a DLL that is used by ASP.Net website). When I use HttpContext.Current inside on of these tasks, it returns with a null value, because the current async thread (or task) was not initiated from a user's request. How can I use HttpContext.Current in these asynchronous threads? P.S - I think my question is more best-practices related than technical.

    Read the article

  • How can i get a list of currently running threads in objective-C(iphone)

    - by krasnyk
    Is there a way to get the list of currently running threads in objective-C? I'm mostly interested in getting the NSThreads objects, cause i want to replace the assertion handler for each running thread? If such thing is not possible, maybe i could set my own selector to be invoked after any thread is spawn(so that i could do the assertion handler replacement over there)?

    Read the article

  • Wait until all threads teminated in ThreadPool

    - by Neir0
    Hi i have this code: var list = new List<int>(); for(int i=0;i<10;i++) list.Add(i); for(int i=0;i<10;i++) { ThreadPool.QueueUserWorkItem( new WaitCallback(x => { Console.WriteLine(x); }),list[i]); } And i want to know when all threadpools threads finished their work. How i can to do that?

    Read the article

  • Number of threads and thread numbers in Grand Central Dispatch

    - by raphgott
    I am using C and Grand Central Dispatch to parallelize some heavy computations. How can I get the number of threads used by GCD? Also is it possible to know on which thread a piece of code is currently running on? Basically I'd like to use sprng (parallel random numbers) with multiple streams and for that I need to know what stream id to use (and therefore what thread is being used).

    Read the article

  • Spawning worker threads

    - by LB
    In C#, How would one go about spawning multiple threads and then sequentially adding results to a list before returning the entire result set? What are some best practices? I'm so far using an ManualResetEvent to signal when the last element has been processed by a thread. But when it returns, I need to have them consolidate the result sets in sequential order so that we don't get into contention issues with the return value list (total results).

    Read the article

  • Iterating Collection In Two Threads

    - by ChloeRadshaw
    This question relates both to C# and Java If you have a collection which is not modified and that collection reference is shared between two threads what happens when you iterate on each thread?? ThreadA: Collection.iterator ThreadA: Collection.moveNext ThreadB: Collection.iterator ThreadB: Collection.moveNext Will threadB see the first element? Is the iterator always reset when it is requested? What happens if this is interleaved so movenext and item is interleaved? Is there a danger that you dont process all elements??

    Read the article

  • Should I use fork or threads?

    - by shadyabhi
    In my script, I have a function foo which basically uses pynotify to notify user about something repeatedly after a time interval say 15 minutes. def foo: while True: """Does something""" time.sleep(900) My main script has to interact with user & does all other things so I just cant call the foo() function. directly. Whats the better way of doing it and why? Using fork or threads?

    Read the article

  • android threads

    - by rantravee
    Hi, I'm searching for some good material on android threads but I couldn't find references for a complete description about this subject. So if you know any valuable reference please point them to me.

    Read the article

  • Best solution for a windows service with constant running threads in C# 4.0

    - by dagda1
    Hi, I want to create a windows service that will create x number of threads that wake up every x number of minutes and do some work. I think the task scheduling or parallel framework is a bad fit for this type of work as it is best suited for work that starts, completes and finishes rather than is constant. Should I look at utilising a thread pool for this approach or does anyone have any advice for a good solution? Thanks Paul

    Read the article

  • C++ boost thread reusing threads

    - by aaa
    hi. I am trying to accomplish something like this: thread t; // create/initialize thread t.launch(); // launch thread. t.wait(); // wait t.launch(); // relaunch the same thread How to go about implementing something like this using boost threads? in essence, I need persistent relaunch-able thread. Thanks

    Read the article

  • Ruby multiple background threads

    - by turri
    I need to run multiple background threads in a thread pool with timeout. The scheme is something like: #!/usr/bin/env ruby require 'thread' def foo(&block) bar(block) end def bar(block) Thread.abort_on_exception=true @main = Thread.new { block.call } end foo { sleep 1 puts 'test' } Why if i run that i get no output? (and no sleep wait?)

    Read the article

  • Python: nonblocking read from stdout of threaded subprocess

    - by sberry2A
    I have a script (worker.py) that prints unbuffered output in the form... 1 2 3 . . . n where n is some constant number of iterations a loop in this script will make. In another script (service_controller.py) I start a number of threads, each of which starts a subprocess using subprocess.Popen(stdout=subprocess.PIPE, ...); Now, in my main thread (service_controller.py) I want to read the output of each thread's worker.py subprocess and use it to calculate an estimate for the time remaining till completion. I have all of the logic working that reads the stdout from worker.py and determines the last printed number. The problem is that I can not figure out how to do this in a non-blocking way. If I read a constant bufsize then each read will end up waiting for the same data from each of the workers. I have tried numerous ways including using fcntl, select + os.read, etc. What is my best option here? I can post my source if needed, but I figured the explanation describes the problem well enough. Thanks for any help here. EDIT Adding sample code I have a worker that starts a subprocess. class WorkerThread(threading.Thread): def __init__(self): self.completed = 0 self.process = None self.lock = threading.RLock() threading.Thread.__init__(self) def run(self): cmd = ["/path/to/script", "arg1", "arg2"] self.process = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1, shell=False) #flags = fcntl.fcntl(self.process.stdout, fcntl.F_GETFL) #fcntl.fcntl(self.process.stdout.fileno(), fcntl.F_SETFL, flags | os.O_NONBLOCK) def get_completed(self): self.lock.acquire(); fd = select.select([self.process.stdout.fileno()], [], [], 5)[0] if fd: self.data += os.read(fd, 1) try: self.completed = int(self.data.split("\n")[-2]) except IndexError: pass self.lock.release() return self.completed I then have a ThreadManager. class ThreadManager(): def __init__(self): self.pool = [] self.running = [] self.lock = threading.Lock() def clean_pool(self, pool): for worker in [x for x in pool is not x.isAlive()]: worker.join() pool.remove(worker) del worker return pool def run(self, concurrent=5): while len(self.running) + len(self.pool) > 0: self.clean_pool(self.running) n = min(max(concurrent - len(self.running), 0), len(self.pool)) if n > 0: for worker in self.pool[0:n]: worker.start() self.running.extend(self.pool[0:n]) del self.pool[0:n] time.sleep(.01) for worker in self.running + self.pool: worker.join() and some code to run it. threadManager = ThreadManager() for i in xrange(0, 5): threadManager.pool.append(WorkerThread()) threadManager.run() I have stripped out a log of the other code in hopes to try to pinpoint the issue.

    Read the article

  • C# - periodic data reading and Thread.Sleep()

    - by CaldonCZE
    Hello, my C# application reads data from special USB device. The data are read as so-called "messages", each of them having 24 bytes. The amount of messages that must be read per second may differ (maximal frequency is quite high, about 700 messages per second), but the application must read them all. The only way to read the messages is by calling function "ReadMessage", that returns one message read from the device. The function is from external DLL and I cannot modify it. My solution: I've got a seperate thread, that is running all the time during the program run and it's only job is to read the messages in cycle. The received messages are then processed in main application thread. The function executed in the "reading thread" is the following: private void ReadingThreadFunction() { int cycleCount; try { while (this.keepReceivingMessages) { cycleCount++; TRxMsg receivedMessage; ReadMessage(devHandle, out receivedMessage); //...do something with the message... } } catch { //... catch exception if reading failed... } } This solution works fine and all messages are correctly received. However, the application consumes too much resources, the CPU of my computer runs at more than 80%. Therefore I'd like to reduce it. Thanks to the "cycleCount" variable I know that the "cycling speed" of the thread is about 40 000 cycles per second. This is unnecessarily too much, since I need to receive maximum 700 messagges/sec. (and the device has buffer for about 100 messages, so the cycle speed can be even a little lower) I tried to reduce the cycle speed by suspending the thread for 1 ms by Thread.Sleep(1); command. Of course, this didn't work and the cycle speed became about 70 cycles/second which was not enough to read all messages. I know that this attempt was silly, that putting the thread to sleep and then waking him up takes much longer than 1 ms. However, I don't know what else to do: Is there some other way how to slow the thread execution down (to reduce CPU consumption) other than Thread.Sleep? Or am I completely wrong and should I use something different for this task instead of Thread, maybe Threading.Timer or ThreadPool? Thanks a lot in advance for all suggestions. This is my first question here and I'm a beginner at using threads, so please excuse me if it's not clear enough.

    Read the article

  • [C++] Producer/Consumer Implementation -- Feedback Wanted

    - by bobber205
    I'm preparing for an interview in a few weeks and I thougth I would give threads in boost a go, as well as do the simple producer/consumer problem I learned in school. Haven't done it quite awhile so I was curious what you guys think of this? What should I add to make it a better example etc. Thanks for the feedback! :) ////////////////////////////////////////////////////////////////////////// boost::mutex bufferMutex; deque<int> buffer; const int maxBufferSize = 5; ////////////////////////////////////////////////////////////////////////// bool AddToBuffer(int i) { if (buffer.size() < maxBufferSize) { buffer.push_back(i); return true; } else { return false; } } bool GetFromBuffer(int& toReturn) { if (buffer.size() == 0) { return false; } else { toReturn = buffer[buffer.size()-1]; buffer.pop_back(); return true; } } struct Producer { int ID; void operator()() { while (true) { boost::mutex::scoped_lock lock(bufferMutex); int num = dice(); bool result = AddToBuffer(num); lock.unlock(); //safe area done if (result) { cout << "Producer " << this->ID << " Added " << num << endl; } else { cout << "!!Buffer was Full!!" << endl; } //Added //Now wait boost::xtime xt; xtime_get( &xt, boost::TIME_UTC); xt.nsec += 1000000 + 100000 * (rand() % 1000); boost::thread::sleep(xt); } } }; struct Consumer { int ID; void operator()() { while (true) { int returnedInt = 0; boost::mutex::scoped_lock lock(bufferMutex); bool result = GetFromBuffer(returnedInt); lock.unlock(); //safe area done if (result) { cout << "\tConsumer " << this->ID << " Took Out " << returnedInt << endl; } else { cout << "!!Buffer was Empty!!" << endl; } //Added //Now wait boost::xtime xt; xtime_get( &xt, boost::TIME_UTC); xt.nsec += 1000000 + 100000 * (rand() % 1000); boost::thread::sleep(xt); } } }; void main() { Producer p, p2; Consumer c, c2; p.ID = 1; p2.ID = 2; c.ID = 1; c2.ID = 2; boost::thread thread1(boost::ref(p)); boost::thread thread2(boost::ref(c)); boost::thread thread3(boost::ref(p2)); boost::thread thread4(boost::ref(c2)); int x; cin >> x; }

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >