aspose file tools*
The moose likes Threads and Synchronization and the fly likes Multithreading and concurrent user requests Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Multithreading and concurrent user requests" Watch "Multithreading and concurrent user requests" New topic
Author

Multithreading and concurrent user requests

Vijay RN
Greenhorn

Joined: Jun 21, 2004
Posts: 2
I am trying to grasp this from past few days but I'm unable to. Please help. Please correct me if any of the following doesn't make sense.

I've a simple static method called Client.getXMLData() which sends a HTTP post request to a website and retrieves information. This method is accessed from non-Java Platform/web page using a customtag.

Under low loads it is working fine but under heavy concurrent user request loads it slows down. I think it is because the requests que-up. (Correct?).

I would like to now convert this to a "multi threaded" program.

The multi-threading examples I've seen shows a client calling the main program which spawns multiple threads to perform multiple tasks. But I've not seen any examples where multiple client requests invoking threads directly.

I think I need a program that behaves like web server, which starts a thread pool and waits for clients.

below is my current code snippet:
---------

webpage: test.cfm
<CFX ... result = Client.getXMLData() >

java class: client
public static String getXMLData() {
//Send HTTP request to http://javaranch.com/xml
//return result;
return result;
}


Hope I'm clear. Thanks. Vijay
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

i think it depends on how the web server is placing calls to your program. Probably the web server is creating a new program for every call. So even if you multithread it, without the cooperation of the web server, its still going to create a totally new instance of the program for each web call.

Perhaps you can look into Java Servlets.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19064
    
  40

Under low loads it is working fine but under heavy concurrent user request loads it slows down. I think it is because the requests que-up. (Correct?).

I would like to now convert this to a "multi threaded" program.


I am assuming that when you say "heavy user request loads", you mean running multiple copies of the client. If this is true, threading the client isn't going to help, as the client is already running in parallel (with multiple processes). Your problem could be on the server side.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Vijay RN
Greenhorn

Joined: Jun 21, 2004
Posts: 2
thanks.

Yes. By saying heavy user requests I meant lots of user requests to the web page (eg: "index.cfm"). index.cfm calls java class/method using web servers custom tag. JVM is installed on same server.

Now when I think about this, I think my question has 2 parts:

part 1- I need to find how webserver calls the java class that runs in JVM. If it starts a separate process for each call then, yes, there is no point "multithreading" the class.

part 2- How do I code a java class that behaves like a "servlet" with the limitation that we don't have servlet/j2ee support in the JVM.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

servlet support is not part of the JVM, its part of the web server. You will need cooperation of the web server, there is no way around it. Well except maybe this

You can create a client server architecture where each call the the webserver creates a client, that calls into your server program. You can perhaps use RMI to achieve this. That way even though the web server will create a new program for each call, that program can be very small, and simply call into your always on server program.

In the end, you will be duplicating the efforts of servlets. Having to re-solve all the issues and such.

Servlets don't need the whole j2ee stuff. in fact they were around before j2ee.

I'd say do the servlets, its your best choice. or you can do the client-server program as i indicated.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multithreading and concurrent user requests