Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-31-2007, 08:19 PM
Member
 
Join Date: May 2007
Posts: 3
lavalleeb is on a distinguished road
Introduction
My name is Bernie Lavallee and I work in a financial institution in Vermont. I've been developing in Java since 1988. I currently develop Web applications in Java using Websphere, Struts, Ajaz, Ibatis and occasionally portlets. I also programmed for 20 years on the IBM miniseries (S38 and AS400).

My question for the forum is as follows:

I have a Java web application which accepts input over several screens and culminates in the production of a PDF document. The production of PDF is a relatively slow process interactively so I've spawned it off to a separate thread provided by a thread pool. It now produces the PDF asynchronously and allows the app to progress quite rapidly.

I've created the thread pool at the servlet context level and within each session request a thread as needed to produce a PDF for that particular session user. Each thread has three class level variables, each containing passed in data needed to populate the PDF's fields.

My question is by creating the threadpool at context or application level am I violating individual session integrity for each user? That is, is the thread acting like a global variable? Should I create the thread pool within each session, although this would seem to defeat the purpose of reducing overhead for each session? I know using class level variables in the thread class is not cool but I know of no other way of passing in the needed data to product the PDF. Any thoughts there as well.

Thanks in advance
Bernie Lavallee
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-31-2007, 09:57 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Hello Bernie,

First of all welcome to java forums and thanks for introducing yourself to us.

I am not much experienced in web development but based on my general java experience and as far as i see, i can say that class level variables (static variables as far as i understood) can obviously a problem when more than one user connects to your web application. At the end, each user's variable will share same data space and the latter one will write the data of previous one.

Cant you send the data you want to the constructor of the thread? If you need to send the data incrementally and cant use constructor, why dont you save thread name in the session, call that thread from the pool whenever you need and update the data of that specific thread?

These are my initial ideas to solve your problem. Let us know the progress..
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-31-2007, 10:10 PM
Member
 
Join Date: May 2007
Posts: 3
lavalleeb is on a distinguished road
Introduction
Thanks for you response.

I do in fact write the data to the thread's constructor but to get it into the run method (which takes no parameters) of the thread I need to store the data in class level variables to make it available.

Bernie
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-31-2007, 10:20 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Quote:
I do in fact write the data to the thread's constructor but to get it into the run method (which takes no parameters) of the thread I need to store the data in class level variables to make it available.
But once you send it to the constructor, you should save the data inside local variables. And after calling start, your thread will be able to reach them via local variables. Am i missing something?

The code will be sth like this:

Code:
class MyThread extends Thread { private String myData1; private int myData2; public MyThread(String myData1, int myData2) { this.myData1 = myData1; this.myData2 = myData2; } public void run() { // Use your local variables here now System.out.println(myData1); } }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-31-2007, 10:25 PM
Member
 
Join Date: May 2007
Posts: 3
lavalleeb is on a distinguished road
Introduction
See what you're getting at. Let me try it out.

Thanks for your comments - very helpful.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-31-2007, 10:29 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Ok. Let us know the progress.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSF (introduction) JavaForums Java Blogs 0 12-08-2007 08:41 PM
Introduction goldhouse IntelliJ IDEA 0 08-09-2007 08:40 PM
JRs Introduction jamesr2b Introductions 4 08-09-2007 07:57 PM
Introduction Swamipsn Introductions 1 08-03-2007 10:57 PM
Introduction goldhouse Lucene 1 05-11-2007 08:10 PM


All times are GMT +3. The time now is 03:02 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org