Solved

Thread Logic?

Posted on 2002-05-08
17
206 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

785 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