multithreading

How do I close a port in a case of program termination?

I am using Socket communication in one of my Java applications.As I know if the program meets any abnormal termination the listening ports does not get closed and the program cannot be started back because it reports "Port already open.." Do I have anyway to handle this problem? What is the general way used to handle this matter? ...

Embeddable Java HTTP Servers

There seems to be multiple extremes when supporting embeddable Java HTTP servers. I have seen minimalist approaches such as NanoHTTPD and leveraging the com.sun.net.httpserver package to attempting to embed Jetty and Tomcat. The ideal embeddable HTTP server would be implemented such that it could be launched via Executor and come with Se...

transaction management with common-j components

We have a Websphere JEE application that requires parallelization, for which we're looking to use CommonJ work components. Each 'thread' would require its own view onto data coming from a database. Most of this would be pre-fetched, but it would still need to go to the database to get some. We anticipate that the duration of the overa...

The good way to control several threads

Hi all, I have a MDI WinForms application that can perform several tasks. Each task is running as a backgroundWorker. What is the good approach to control the running threads: check whether the specific thread is running stop specific thread ? For example it shouldn't be possible to run the same task simultaneously. May be I need ...

How to synchronize between main and worker thread in Qt?

I have this design. I could not achieve what I need: B is inherited from A. A is inherited from QThread. My goal is restart(re-run) to "worker" thread when it has finished its task. I intend to call the worker thread destructor for this approach because, it takes memory from heap. I need to clean-up all the related variables. How c...

Winforms listbox not updating when bound data changes

The image below shows how my code works. When I press button2 the listbox is updated, but not when I press button1. Why? Is the problem threading related? If it is, where should I add the call to (Begin)Invoke? One interesting thing to note is that if I first press button1 and then button2 the data generated by the button1 click is s...

Are there known issues with using sqlite and file locking on different platforms?

I'm using sqlite to do an index of a proprietary file, and the database will be accessed with multiple threads (using different sqlite handles) for reading and writing. I know that sqlite locks the file in order to provide concurrency for readers/writers, and depends on the OS file api for locking. This is all fine on windows and linux...

Running 2 threads simultaneously

In the case of an IM client. I have made 2 separate threads to handle sending packets (by std io) and receiving packets. The question is how to make these 2 threads run simultaneously so that I can keep prompting for input while at the same time be ready to receive packets at any time? I have already tried setting a timer but the data...

Is there a way to enforce an atomic operation with no context switch in c#?

I have several lines of a method that I would like to ensure that there is no context switch to another thread while executing these? Yes, re-architecting is an option but it would be far more expedient for now if I could do this. Is this possible? If not then does anyone know the reasoning behind the decision? Edit: The reason I am ...

How to start Java from within a C process?

I want to add some Java (actually Clojure) based event handlers to a HUGE legacy C application. What is the most straight forward and easily maintained way to do this? I would like the Java classes to be running in the same process as the C code. Is this even possible? ...

How does Invoke work underneath? Doesn't thread have only 1 instruction pointer?

Hello all, I would like to know how it is possible that C# Invoke function can work (I am now considering the call from worker thread to invoke a method that manipulates GUI from GUI thread): Assume I have two threads, and each one of them has it's inctruction pointer, pointing on an instruction that is currently executed. Now, I call...

How to Suspend a button event in C#?

In my application I want to suspend a button event for some time so that I can fire another event after which the first button event will resume. In c# I am not getting how do I perform it using threads asynchronously. Please help. Thanks in advance.. ...

How to create a thread in a class?

Is there a template that can be used to create threads when we program in OO language ? How to go about designing a threading package for an OO language? ...

What is mutex and semaphore in Java ? What is the main difference ?

What is mutex and semaphore in Java ? What is the main difference ? ...

How to design a threading package for an OO language?

It seems difficult to design a threading package in OO class than in functional programming. ...

Any lib for multi-threading cross-platform for Delphi AND FreePascal?

I'm aware of some Windows Thread Libs for Delphi(OmniThread Lib, BMThreads, etc). But is there a lib that is built to be cross-platform and that can both be used under Delphi and FreePascal? ...

More threads, better performance?

When I write a message driven app. much like a standard windows app only that it extensively uses messaging for internal operations, what would be the best approach regarding to threading? As I see it, there are basically three approaches (if you have any other setup in mind, please share): Having a single thread process all of the me...

How can I implement a threaded UDP based server in Java ?

How can I implement a threaded UDP based server in Java ? Basically what I want, is to connect multiple clients to the server, and let each client have his own thread. The only problem is, that I don't know how to check if a client is trying to connect to the server and spawn a new thread for it. boolean listening = true; System.out.p...

Implementing worker threads (in Linux): How offensive is this?

#include <pthread.h> static void * worker_thread(void *); void some_func(void) { pthread_t * tmp; tmp = malloc(sizeof(pthread_t)); if (NULL != tmp) { if (!pthread_create(tmp, NULL, worker_thread, (void *)tmp)) pthread_detach(*tmp); else free(tmp); } } static void * worker_thre...

Profiling disk access

Currently I am working on a MFC application which reads and writes in to the disk. Sometimes this application runs amazingly fast and sometimes it is damn slow. I am guessing that it is because of the disk access involved, hence I want to profile it. These are some questions in this regard: (1).Currently I am using AQTime profiler to pr...