• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multithreading and concurrent user requests

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Vijay RN
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic