Interesting. Back in the bad old days when I had to use the free HomeBase
server (now owned by Iona and defunct) I tried using static variables in my
beans.
I observed behaviour compatible with what you're describing, although I
didn't have anything like your detailed understanding of the reasons for
it.
In my current use of Jonas I have to pull out autonumbered values in some
ejbPostCreates, and am simply using a fresh SELECT MAX query each time. My
instinct is that the overhead involved in this is trivial, and is far
outweighed by the potential problems of using statics.
If you do need to do this kind of caching, I guess the kosher approach
would be to use an appropriate stateful session bean as the cache.
Joe
-----Original Message-----
From: Jens Riboe [SMTP:[EMAIL PROTECTED]]
Sent: Thursday, March 30, 2000 3:37 PM
To: Albert Brotzer; Guillaume Rousse
Cc: [EMAIL PROTECTED]
Subject: SV: server generated primary key
>> in fact we already use a table with a field for each table. This
>> works quite good. Thanks for the idea to cache it via a static field.
Some comments regarding static fields in ejb objects.
1) Static fields are critical sections.
That means (in the general case) they must be managed by a synchronized
block.
This synchronization may conflict with the container's synchronization.
2) Static fields belongs to a Class object and Class objects belongs to a
ClassLoader.
That means (in the general case) it's possible to have two (or more)
different static values - one for each ClassLoader. In a "normal" Java
program
this scenario is unlikely.
However, sooner or later the bean, with static
non-constant fields, executes inside a container performing dynamic
class reloading. Depending on the implementation details it may happen
that
an "old" bean belonging to an "old" class loader co-exists with a "new"
bean
belonging to a "new" class loader.
That, is a pretty nasty bug to find!
I have read somewhere, that beans shouldn't have static fields.
At least no non-constants.
Anyone agree?
Best regards,
Jens Riboe
-------------------------------------------------------
Jens Riboe / Ribomation AB
-------------------------------------------------------
Email: [EMAIL PROTECTED]
WWW : http://www.ribomation.se/
Phone: 08-754 67 70 (Int. +46-87546770)
Fax : 08-754 67 71 (Int. +46-87546771)
Visit: Bergkallavagen 32, Bredden/Sollentuna/Stockholm
-------------------------------------------------------
Ribomation AB
Box 303
SE-19230 SOLLENTUNA
Sweden
-------------------------------------------------------
<< File: Jens Riboe.vcf >>
----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".