I’m working to make a crawler in Java. I made a single-threaded crawler to visit a single page and fetch all links on that page. Now I want to make it multi-threaded but facing difficulties. In the …
Tag: multithreading
Java Chat Multi-Client Receiving thread
In a lot of multclient java programs people use a separate thread which only receives the messages from the server. Is it really necessary? Why can’t it be done in the main thread? What should be the …
Fast and asynchronous way of making multiple http requests in JAVA
I have a program that should make really fast http requests. Requests should be made asynchronously so that it won’t block the main thread. So I have created a queue which is observed by 10 separate …
Thread is interrupted by calling interrupt(), but Thread.isInterrupted() returns false
I am testing InterruptedException with the following test code: Runnable runMe = new Runnable() { @Override public void run() { for(int i=0; i<6; i++) { System.out....
Spring dynamically choosing between data sources (alternative to ThreadLocal)
I’ve read about AbstractRoutingDataSource and the standard ways to bind a datasource dynamically in this article: public class CustomerRoutingDataSource extends AbstractRoutingDataSource { @…
TCP threaded server/client
I’m trying to make a threaded TCP server that accept multiple client. It’s only accepting one client. Any idea on how to make the server accepting multiple client? Here is what I tried so far: I …
Partition a Set into smaller Subsets and process as batch
I have a continuous running thread in my application, which consists of a HashSet to store all the symbols inside the application. As per the design at the time it was written, inside the thread’s while true condition it will iterate the HashSet continuously, and update the database for all the symbols contained inside HashSet. The maximum number of symbols
Run Handler messages in a background thread
I want to run some Runnable in a background thread. I want to use Handler because it’s convenient for delays. What I mean is handler.post(runnable, delay); Where runnable should be run in background …
Tips to prevent deadlocks in java
I am studying java threads and deadlocks, I understand deadlock’s examples but I wonder if there are general rules to follow to prevent it. My question is if there are rules or tips that can be …
Java Thread Sleep and Interrupted Exception
Why does a sleep thread need a try catch to catch Interrupted Exception? Why does a sleep even emit an Interrupted Exception error? This are the two questions I really wanna find out about in java …