0

threads and com.potix.zk.ui.util.Initiator

asked 2006-04-05 21:17:11 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3671537

By: dzasypkin

Hi,

Seems that doFinally() method of com.potix.zk.ui.util.Initiator is invoked not in the same thread as doInit() method.

If this is the case, it would be nice to have something similar to EventThreadInit/EventThreadCleanup for initial page rendering process.

It would allow binding Hibernate session to the thread initially and closing it after page rendering finishes. So that standard Spring-Hibernate sessions/transactions approach could be applied including getCurrentSession() method of Hibernate session factory and lazy data loading during page construction.

Regards,
Dmitri


delete flag offensive retag edit

10 Replies

Sort by ยป oldest newest

answered 2006-04-05 22:04:11 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3671612

By: oberinspector

Hello Dmitri,

i have written a feature request for this...
http://sourceforge.net/tracker/index.php?func=detail&aid=1464346&group_id=152762
&atid=785194

and a preliminary HowTo...
http://en.wikibooks.org/wiki/ZK/How-Tos/HowToHandleHibernateSessions
the sources have been improved inbetween in some way...

there is also a small talk about hibernate/spring integration, but as i remember the session handling is not covered...

I close the session with EventThreadCleanup, but for a normal request/response cycle, i think there is no zk solution yet... of course one can write a normal sevelet filer, or probably use the spring filter... this is also an open point on my todo list...

as workaround DesktopCleanup could be used in between...

regards,
thomas



link publish delete flag offensive edit

answered 2006-04-05 22:08:47 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3671615

By: oberinspector

BTW... remove the ";" character between "&" and "a" from the first URL... sourceforge forum has some quirks... ;)

link publish delete flag offensive edit

answered 2006-04-06 08:35:17 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3672251

By: tomyeh

They are invoked in the same thread. Would you show me what make you think so?
There might be a bug there.

link publish delete flag offensive edit

answered 2006-04-06 12:15:56 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3672502

By: dzasypkin

Hi Thomas,

Thank you very much for the info and for that How-To.

It turned out it was my mistake. Now everything works great - I open Hibernate session in doInit() and close it in doFinally() methods of com.potix.zk.ui.util.Initiator implementation. And both methods run in the same thread, so I can utilize all the stuff which requires a thread bound session.

Regards,
Dmitri



link publish delete flag offensive edit

answered 2006-04-06 12:19:02 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3672507

By: dzasypkin

It turned out it was my mistake. Sorry I havent thoroughly tested my code before posting here.

Regards,
Dmitri



link publish delete flag offensive edit

answered 2006-04-06 12:47:29 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3672538

By: oberinspector

yes maybe this doFinaly is a good place und sufficient... for event initiated hibernate sessions the EventThreadCleanup could be used...

As i understand the Intiator it is related to a zul file or to a page(???)...
and the doFinally() is called, when the page rendering has finished (???)...
so when a desktop is build up from different zul files/pages from db it could happen, that more then one hibernate sesion create/close can happen during one request/response cycle, which obviosly no good...

so when my assumtions are right it would be better to have only one Initiator in the root zul file/page, which builds up the desktop and only implement doFinally to close the hibernate session as in my EventThreadCleanup... every subpage could create/retrieve a hibernate session from my HibernatSessionOwner on demand and let the HibernatSessionOwner care for further usage...


link publish delete flag offensive edit

answered 2006-04-06 12:54:44 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3672550

By: tomyeh

Yes, you are correct.

link publish delete flag offensive edit

answered 2006-04-06 13:04:23 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3672566

By: oberinspector

thanks!... i will try this out...

probably we don't need the feature request for the asynchronous update cleanup...

regards, thomas

link publish delete flag offensive edit

answered 2006-04-08 17:48:02 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3676364

By: dzasypkin

Testing has revealed some unexpected behavior: doFinally() method of the root page is called *before* all child pages' doInit() method calls. Seems like ZK posts rendering of child pages to the end of its internal event queue.

For example, given a simple three page hierarchy like this "page1 includes page2 which includes page3" causes the following sequence of calls:
----------------------------------------------
doInit() of page1 Initiator
<zscript> Java code embedded in page1
doFianlly() of page1 Initiator
doInit() of page2 Initiator
<zscript> Java code embedded in page2
doFianlly() of page2 Initiator
doInit() of page3 Initiator
<zscript> Java code embedded in page3
doFianlly() of page3 Initiator
----------------------------------------------

Another interesting thing is about manual refresh of inner pages which is described in ZK How-Tos. I found that the root event's EventThreadCleanup is called *before* the child page refresh starts.

Thus we have a problem. Closing Hibernate session in each doFinally method is not a good idea (thanks Thomas for pointing this out). Specifically this might prevent utilizing lazy load feature during child pages rendering.

So for now the best place to close Hibernate session after initial desktop rendering seems to be a specially designed ServletFilter - for example Spring's OpenSessionInViewFilter intended for the "Open Session in View" pattern.


link publish delete flag offensive edit

answered 2006-04-09 01:43:31 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3676716

By: henrichen

Hi Dimitriy,

You are correct. The included page is not handled "in the place". They are handled at the rendering phase of the "root" page. The major reason is that the <include> component can be used to include any kind of page (jsp, html, ...) besides zuml page; therefore we have to delay the "including" until then.

A new component named <macro> in planning might solve this issue because it would allow only zuml page and should be handled "in the place".

/henri


link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2006-04-05 21:17:11 +0800

Seen: 242 times

Last updated: Apr 09 '06

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More