Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading diff. images in a webpage using servlet  RSS feed

 
Srikanth Penta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know how diff. images are loaded using threads to a web page using servlet.

I want to make the loading process fast by using multiple threads. Is it using file io?

Can anyone please give me some idea on this?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that the question is not very clear.
 
Srikanth Penta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not saying clearly,

I want to display 20 images in single page. Its taking more time. So I want to make that process fast by using threads. i.e want to reduce the loading time of the page.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on the actual problem, it isn't really a Servlet or Java question.

Firstly, most resources in a page tend to be loaded from the client using a single 'keep alive' connection since this is faster and more efficient than trying to negotiate a new connection for each resource. There are some exceptions to this since some resources need to be completely loaded (eg javascript files) before related files can be determined.

Secondly, clients and servers tend to limit the connections allowed to prevent one page or client hogging the system. Hence even if you managed to force many connections to be created from the client, the third onwards may be blocked until the first ones finish.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the client in your case is browser then you cannot do anything , you cannot enforce and restriction from the server side.

As establishing TCP/IP connection is a costly affair , so it keep the connection open and uses the same for getting other resources for constructing the page.Now sure whether browsers use multthreading for requesting multiple resources at a time.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you certain that the problem is not one of limited bandwidth - how big are the images, and what kind of connection is used?

Also, I don't think a browser would use N download threads to download N images. For a given web page, I think no more than about 4 threads are used by default. Some browsers have a setting for this.

As to addressing the problem on the server, typical web containers like Tomcat already use a pool of threads to handle requests. So if 20 requests come in (unlikely, see above) the server might well be using 20 threads to serve them. The same is true if the images aren't static, but are generated dynamically by a servlet (which is multi-threaded by nature, unless SingleThreadModel or synchronization is used).
[ May 04, 2007: Message edited by: Ulf Dittmer ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!