• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

Thread Logic?

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
barnarp
Asked:
barnarp
  • 7
  • 6
  • 2
  • +2
1 Solution
 
aKaCommented:
what server are you using?
0
 
barnarpAuthor Commented:
I'm using IIS 5.1 with tomcat 403 running Oracle 8
0
 
objectsCommented:
> 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
sey7Commented:
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
 
barnarpAuthor Commented:
hi

keep getting Method flush() not found?
0
 
heyhey_Commented:
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
 
heyhey_Commented:
> keep getting Method flush() not found?

OutputStream.flush()
0
 
barnarpAuthor Commented:
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
 
heyhey_Commented:
> 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
 
sey7Commented:
You can place a part of your source so I can modify it?
0
 
barnarpAuthor Commented:
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
 
heyhey_Commented:
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
 
barnarpAuthor Commented:
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
 
heyhey_Commented:
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
 
barnarpAuthor Commented:
thanks hey for all your help again seems like the best solution.
0
 
heyhey_Commented:
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
 
heyhey_Commented:
contact me at heyhey_@iname.com and I'll forward to you on complicated SQL statement.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 6
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now