Solved

Thread Logic?

Posted on 2002-05-08
17
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

705 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