Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!

mariqn nenchev

+ Follow
since Apr 17, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by mariqn nenchev

Hi, all
i need to develop the following:
PriceProcessor that starts in separate thread and generate prices for List of items that must be send to another module. The price generation is long task, so i separated it to another class that implements Runnable . What i want is to make the PriceProcessor in while(isRunning) loop to start list of Price runnables (the list is created by algorithm that says how many runnables to be created) and while the runnables from the list are not finished the processor must not generate new prices for the items(the prices must be generated as frequently as possible). So i want to use This ThreadPoolExecutor but the problem is that i don't know how to tell him that he must run list of runnables and wait all of them to finish before to execute the new list of runnables:
PriceProcessor pp = new PriceProcessor();
Items items = new Items(List<Integer> itemids);
// here i make request to the price processor to begin generating prices for that items
pp.process(items); // this will be called 1 time a day to update the items list with new items. The price processor will use the current items if new didn't arrived. This is like self generating task

public class PriceProcessor() extends Thread {
private BlockingQueue<Items> blockingQueue = new ArrayBlockingQueue<Items>(1);

public SelfTaskGenMultiThreadedProcessor(TaskThreadPooledExecutor executor) {
this.executor = executor;

public void process(Runnable target) {
try {
} catch (InterruptedException e) {

public void run() {
isRunning = true;
while (isRunning) {
try {
items = blockingQueue.take();
// all runnables must be executed before the next loop
List<Runnable> runnables = createRunnables(items);
if (runnables != null) {
synchronized (runnables) {
for(runnables loop)
//wait for all runnables from above to finish and then simulate new request for the same items if new once didn't arrived(the queue has size 1 so if durring the upper loop new items didn't arrived // the current onces are used)
synchronized (blockingQueue) {
if (blockingQueue.isEmpty()) {
} catch (InterruptedException e) {


So the main question is how to make the ThreadPoolExecutor to wait all runnables from the list to finish and then go on and create new list of runnables. NB: The number of runnables depends on the items size and type.

My fault, the log message is not correct. By that i mean th main thread that must wait for the other five threads to finish and that time = the longest request execution time. I will edit my first message.

Martijn Verburg wrote:It looks like from your logging that you're creating 5 connections per thread, don't you want a connection per thread?

OK, i read it and i added this param http.connection.stalecheck = false, i can't determine if there is some improvement in the performance time.
But my question is why every next request has bigger time to execute, please have a more detailed look at my first post. I think that the problem may be hidden in this debug line:
2009/04/21 14:23:05:789 EEST [DEBUG] ConnPoolByRoute - Notifying thread waiting on pool [HttpRoute[{}->]]
What does it mean? The Thread is waiting to get connection from the pool, and that is why every next request is executed with bigger time?
Can you tell me how to initialize 5 connections that are ready to use immediately, because i think that the http client looks at the pool for connection and it either wait connection to be released or creates new on demand. How can i create for example 5 connections and if more are needed that the client will create them on demand. Or may be i am wrong, have a look at my code please.
OK, here you are. I posted the code in code tags, now could you please help me.

Could you edit your post and UseCodeTags? That'll help us read your question better
Hi, all.
I am new with httpclient. I am using version 4. What i am trying to do
is the following:
Every 10 seconds i have to send usually about 10-15 get requsets. Every
Request returns me a response as (small) xml content that i parse and use.
So i create httpclient singleton with ThreadSaveClientConnManager, and i
have MyThread class that in its run method create HttpGet and the client
executes it. I have ThreadManager that starts the constructed threads.I
printed the times for building and executing the requests and they seems
to increase, and i can't understand why. Am i missing something, or i
don't free resources?
Here is my code:

In the thread class run method i do this:
HttpGet request = new HttpGet(query);// where query is some uri string
in format
HttpResponse response = httpClient.execute(request);
stream = response.getEntity().getContent(); // this input
stream is the xml i need.
in the finally block i only close the inputstream.

The docs says that if i close the input stream i close the underling
connection to be reused by the client is that right? Notice that my http
client and thread conn manager are singletons.
An the problem is that every request time is increased, but i can't
understand why some leak maybe, i don't free resources?!?
Here is the time in milliseconds for my first 2 threads:
first portion of get requests(the requests must be send every 10 seconds)
Createing and executing get for: 136
Createing and executing get for: 136
Createing and executing get for: 380
Createing and executing get for: 466
Createing and executing get for: 542
second portion of get requests(the requests must be send every 10 seconds)
Createing and executing get for: 677
Createing and executing get for: 755
Createing and executing get for: 784
Createing and executing get for: 1010
Createing and executing get for: 1015
third portion of get requests(the requests must be send every 10 seconds) the execution of the request is still increasing. >1 sec

I have to say that the time is very important for the application. The
first requests times are acceptable, but they seems to increase. I
printed only the time in witch the request is constructed from query
string and is executed by the httpclient.
I also used debug config for that httpclient and here is part of it:
[DEBUG] ConnPoolByRoute - Notifying thread waiting on pool [HttpRoute[{}->]]
Could this be the reason that evey next request takes mote time? What the above means?
Please could you help with suggestions.