Results 1 to 6 of 6

Thread: Introduction

  1. #1
    lavalleeb is offline Member
    Join Date
    May 2007
    Posts
    3
    Rep Power
    0

    Default 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

  2. #2
    levent Guest

    Default

    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..

  3. #3
    lavalleeb is offline Member
    Join Date
    May 2007
    Posts
    3
    Rep Power
    0

    Default 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

  4. #4
    levent Guest

    Default

    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:

    Java 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);
    
        }
    
    }

  5. #5
    lavalleeb is offline Member
    Join Date
    May 2007
    Posts
    3
    Rep Power
    0

    Default Introduction

    See what you're getting at. Let me try it out.

    Thanks for your comments - very helpful.

  6. #6
    levent Guest

Similar Threads

  1. Introduction
    By goldhouse in forum Lucene
    Replies: 2
    Last Post: 01-17-2010, 12:56 PM
  2. Introduction
    By goldhouse in forum IntelliJ IDEA
    Replies: 0
    Last Post: 08-09-2007, 07:40 PM
  3. JRs Introduction
    By jamesr2b in forum Introductions
    Replies: 4
    Last Post: 08-09-2007, 06:57 PM
  4. Introduction
    By Swamipsn in forum Introductions
    Replies: 1
    Last Post: 08-03-2007, 09:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •