Solved

Thread Logic?

Posted on 2002-05-08
17
204 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
json format text only 4 65
java  and programming certification ? 4 65
solarwind tftp server 2 32
Java Loop 4 22
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now