Solved

Thread Logic?

Posted on 2002-05-08
17
207 Views
Last Modified: 2012-05-04
Hi,

I call a thread class in a jsp page.

The Thread runs a query on the database, insert the results in an arraylist, and returns the arraylist to the jsp page.

The JSP Page inserts the arraylist in a session.

Now all this works fine, except that the page "waits" for the thread to return the arraylist , before it displays anything on the page?

I must be doing something wrong, as this defeats the purpose of the thread?

The content of the page should be displayed whilst the thread is doing the prosessing in the background,. I think

Any help please.
0
Comment
Question by:barnarp
  • 7
  • 6
  • 2
  • +2
17 Comments
 

Expert Comment

by:aKa
ID: 6995878
what server are you using?
0
 

Author Comment

by:barnarp
ID: 6995894
I'm using IIS 5.1 with tomcat 403 running Oracle 8
0
 
LVL 92

Expert Comment

by:objects
ID: 6995959
> The content of the page should be displayed whilst the
> thread is doing the prosessing in the background,.
> I think

Why do you think that?
The jsp is responsible for generating the contents of the page, so if the jsp waits for the thread to complete then how can anything be displayed.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 1

Expert Comment

by:sey7
ID: 6995967
You can use "flush()" method for your connection to display the first part of your page, and after your thread ends you can process the results and flush() again.

With some modifications you can process your data in the thread and use "flush()" there.

0
 

Author Comment

by:barnarp
ID: 6996195
hi

keep getting Method flush() not found?
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6996231
best solution is to return immediately
"Wait - calculating ..." page that will refresh itself each second until it loads real result.

relying on the fact that browser will displayed partially generating HTML page is not very good idea.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6996233
> keep getting Method flush() not found?

OutputStream.flush()
0
 

Author Comment

by:barnarp
ID: 6996251
Thanks for all the help sofar.

now I get:

Can't make static reference to method void flush() in class java.io.OutputStream.
                OutputStream.flush() ;
I think refreshing "Wait - calculating ..." page will be too annoying for users?!
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6996257
> Can't make static reference to method void flush() in class java.io.OutputStream.

try
response.getOutputStream().flush();


> I think refreshing "Wait - calculating ..." page will be too annoying for users?!

more annoying that browser window that does not show anything ?
0
 
LVL 1

Expert Comment

by:sey7
ID: 6996262
You can place a part of your source so I can modify it?
0
 

Author Comment

by:barnarp
ID: 6996301
The whole issue came about when I saw that populating dbresults (7000 records) in a bean and returning the results to a " show 20 records at a time" page took too long.

The first time the page is opened, the user has to wait a long time for the first 20 results (in essence the whole arraylist is loaded) to display. Obviously displaying records 20-40 etc is quick, cause it reads from the arraylist.

Thats why i tried to find a faster way to display the results!

It seems all other options wont work 100%?

-  "Wait - calculating ..."  page will cause flicker.
- Thread will mean that if the user does not give it enough time to run in the background, he will only receive some of the results.
- Vector is even slower than arraylist.

Seems "waiting" will be the best in the end?
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6996306
you can probably redesign the system to return the page immediatelly after loading first 20 records and leave the thread to load the rest of the data.
0
 

Author Comment

by:barnarp
ID: 6996339
hey,

have thought of that before, but have the following problem.

I do the following query:
select laborcode,name from labor order by name

I get results in alphabetical order.

The only query I can do to get the first 20 results is:

select laborcode,name from labor where rownum < 20 order by name

which wont give me the same first 20 results as that of the first query.

Database is Oracle.

0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 50 total points
ID: 6996359
no, no.

start your query, when you receive first 20 elements, pack them inside a bean, return them to caller and continue extracting the other results.

but if you are using oracle, you can probably find pure SQL solution.
0
 

Author Comment

by:barnarp
ID: 6996478
thanks hey for all your help again seems like the best solution.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6996504
you can make with miracles with SQL in oracle. you should be able to request only rows 40-79 from some query - I asked a friend for some help.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6996523
contact me at heyhey_@iname.com and I'll forward to you on complicated SQL statement.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 42
servlet  URL Rewriting 1 42
jdbc error in jsp application 20 64
how to install java on RHEL image on EC2 4 42
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question