multithreading

Web image loaded by thread in android

I have an extended BaseAdapter in a ListActivity: private static class RequestAdapter extends BaseAdapter { and some handlers and runnables defined in it // Need handler for callbacks to the UI thread final Handler mHandler = new Handler(); // Create runnable for posting final Runnable mUpdateResults = new Runnable() { ...

C# Locking an object that is reassigned in lock block

Hello, I have this code in a class: private static MyObject _locker = new MyObject(); ... lock (_locker) { ... _locker = new MyObject(); ... } Will it keep the lock on _locker ? ...

Built in background-scheduling system in .NET?

I ask though I doubt there is any such system. Basically I need to schedule tasks to execute at some point in the future (usually no more than a few seconds or possibly minutes from now), and have some way of cancelling that request unless too late. Ie. code that would look like this: var x = Scheduler.Schedule(() => SomethingSomethin...

Best ways to write a method that updates two objects in a multithreaded java environment?

Suppose we have a class called AccountService that manages the state of accounts. AccountService is defined as interface AccountService{ public void debit(account); public void credit(account); public void transfer(Account account, Account account1); } Given this definition, what is the best way to implement transfer() so that y...

mulithreading in android

How to implement Multithreading in Android application so as to increase responsiveness of UI. ? ...

how to join thread working with another one

Hi all, I have a thread changes in a control in a form in a windows forms application, I implement the invoke method for prevent threading cross access, but when I close the form, the second thread still work and try to access to the control and throw an object reference not set to an instance of object exception how can I assure pre...

PHP database simulation

I have a PHP script that works by calling items from a database based upon the time they were placed in there and it deletes them if they are older than 5 minutes. Basically, I want to now simulate what would happen if this database was being updated regularly. So I was considering sticking in some code that loads an XML file then goes ...

Trying to run multiple HTTP requests in parallel, but being limited by Windows (registry)

I'm developing an application (winforms C# .NET 4.0) where I access a lookup functionality from a 3rd party through a simple HTTP request. I call an url with a parameter, and in return I get a small string with the result of the lookup. Simple enough. The challenge is however, that I have to do lots of these lookups (a couple of thousan...

Why does java.util.concurrent.ArrayBlockingQueue use 'while' loops instead of 'if' around calls to await()?

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 instead of signal(), but if only one thread at a time is notified, how can this go wrong? Their code here - check out the put() and take() methods; a simpler and more-to-the-point...

what's wrong with my producer-consumer queue design?

I'm starting with the C# code example here. I'm trying to adapt it for a couple reasons: 1) in my scenario, all tasks will be put in the queue up-front before consumers will start, and 2) I wanted to abstract the worker into a separate class instead of having raw Thread members within the WorkerQueue class. My queue doesn't seem to disp...

NSTimer as a timeout mechanism

I'm pretty sure this is really simple, and I'm just missing something obvious. I have an app that needs to download data from a web service for display in a UITableView, and I want to display a UIAlertView if the operation takes more than X seconds to complete. So this is what I've got (simplified for brevity): MyViewController.h @inte...

.NET 1.0 ThreadPool Question

I am trying to spawn a thread to take care of DoWork task that should take less than 3 seconds. Inside DoWork its taking 15 seconds. I want to abort DoWork and transfer the control back to main thread. I have copied the code as follows and its not working. Instead of aborting DoWork, it still finishes DoWork and then transfers the contro...

Linked list example using threads

I have read the following code of using CRITICAL_SECTION when working with multiple threads to grow a linked list. what would be the main() part which uses two threads to add to linked list? #include <windows.h> typedef struct _Node { struct _Node *next; int data; } Node; typedef struct _List { Node *head; CRITICAL_SEC...

How refresh a DrawingArea in PyGTK ?

I have an interface created with Glade. It contains a DrawingArea and buttons. I tried to create a Thread to refresh every X time my Canva. After a few seconds, I get error messages like: "X Window Server 0.0", "Fatal Error IO 11" Here is my code : import pygtk pygtk.require("2.0") import gtk import Canvas import threading as T impor...

Crash after pop'ing stack while a threaded NSURLConnection is open

Error Log says: bool _WebTryThreadLock(bool), 0x3c689f0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now... App structure: worker threads are detached from the MainThread as new data is needed via user interaction, eac...

Getting data from JFrame AFTER the form is filled

I'm trying to get data for my application from a form set in an external window (getDataWindow extends javax.swing.JFrame). The problem is that functions are executed before form is filled in. getDataWindow dataW=new getDataWindow(); dataW.setVisible(true); size=dataW.returnSize(); I've tried also adding additional boolean...

ClassCastException with JDialog and Thread

I have a JDialog with a thread in it. It sporadically gives me a ClassCastException when the dialog is created (which means I can have succesful ones with no exception), and I have no clue to where it should occur. Here's a snippet of my JDialog class public class ConfirmExitDialog extends JDialog implements Runnable, ActionListen...

Should I pass a SqlDataReader by reference or not when passing it out to multiple threads.

Hi all, being new to c# I've run into this 'conundrum' when passing around a SqlDataReader between different threads. Without going into too much detail, the idea is to have a main thread fetching data from the database (a large recordset) and then have a helper-task run through this record by record and doing some stuff based upon the...

Is there a straightforward way to have a thread-local instance variable?

With the ThreadStatic attribute I can have a static member of a class with one instance of the object per thread. This is really handy for achieving thread safety using types of objects that don't guarantee thread-safe instance methods (e.g., System.Random). It only works for static members, though. Is there any straightforward way to d...

Is it possible to create thread-safe collections without locks?

This is pure just for interest question, any sort of questions are welcome. So is it possible to create thread-safe collections without any locks? By locks I mean any thread synchronization mechanisms, including Mutex, Semaphore, and even Interlocked, all of them. Is it possible at user level, without calling system functions? Ok, may b...