| CARVIEW |
|
globalenvironment
|
| Summary | Global Environment For J2EE |
|---|---|
| Categories | None |
| License | GNU General Public License (GPL v. 2.0) |
| Owner(s) | weijiang |
Message from the owner(s)
GlobalEnvironment
Overview
GlobalEnvironment is a global version of regular Properties and Hashtable. java.util.Properties and java.util.Hashtable are valid within one single Java VM. GlobalEnvironment is valid across the whole network in distributed computing environment.
In the J2EE world, the environment values are very rigid. The initial parameters for EJBs and JSPs are in deployment descriptors. They can be changed at deploy time only. They are not shareable among different distributed components. Using GlobalEnvironment as static values, you can make your program more flexible. GlobalEnvironment can be used as dynamic values as well. GlobalEnvironment is a family of utility classes. It consists of:
This family provides globally shared key-value pairs. These pairs areGlobalDouble GlobalHashtable GlobalLong GlobalObject GlobalProperties
available for different
See GlobalProperties for details.Java threads JVMs, EJBs (Enterprise Java Beans) JSPs (Java Server Pages) Java applications non-Java applications.
GlobalEnvironment is designed to be vender and platform neutral.
GlobalEnvironment has most of applicable methods from
java.util.Properties and java.util.Hashtable. The method
signatures are similar, but with a java.sql.Connection as the first
parameter.
Other options
When we come to this point, you may say that there is a performance penalty to access database dynamically. Yes, compare to memory operation in a single JVM. But if you want the key-value pairs valid across the network for different JVMs, you need to keep them in a central place. If you want them to be persistent, you need to store them in a data source. Database is the best choice.
Some programs store user object in JNDI tree. But that is even more expensive. Many clustering use multicast for clustering communication. Storing large objects within the JNDI tree can overload multicast traffic and interfere with the normal operation of a cluster.
There is a new class Preference in JDK 1.4. But neither JNDI or Preference will allow you to combine environment changes and your business data changes in one transaction, so you can not COMMIT or ROLLBACK.
Thread safe and thread friendly
The methods increase in both GlobalDouble and GlobalLong provide
a thread friendly functionality on top of thread safe behavior: a thread will
not overwrite changes from other threads. For example, you have an attribute
"totalSale". The current value is 10.00. Now you sold something for 2.00 and
your coworker sold something for 5.00 at the same time. If you do:
read totalSale and get the value 10.00
write totalSale as 10.00 + 2.00
and your coworker does similarly, then the result will be either 12.00 or 15.00,
not 17.00.If you use method
increase, do not read, do not write, but:
increase by 2.00and your coworker does similarly, the result will be 17.00, regardless of who gets the transaction first.
Other information
There is some related information:
| Powered by CollabNet | Feedback |
FAQ |
Press |
Developer tools
© 1995 - 2007 CollabNet. CollabNet is a registered trademark of CollabNet, Inc. |
