tag:blogger.com,1999:blog-7285317616038314832024-03-08T22:59:20.378-08:00Java + Cloud + AIvarious topics on java, spring, machine learning and so onShaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-728531761603831483.post-85366312253530338982020-09-14T08:12:00.004-07:002020-09-14T11:51:47.436-07:00AWS useful articles<p> Lambda with RDS </p><p> https://www.jeremydaly.com/reuse-database-connections-aws-lambda/</p><p> https://www.jeremydaly.com/manage-rds-connections-aws-lambda/</p><p> Good part:</p><p> database connection management recommendation</p><p> Added Value:</p><p> https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/rds-proxy.html</p><p> (This seems like a DB connection pool management)</p>Shaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.com1tag:blogger.com,1999:blog-728531761603831483.post-11172923843044923542020-07-22T09:13:00.002-07:002020-09-14T08:09:35.135-07:00SQL vs NOSQL (DynamoDB)This is not about the detailed comparison between SQL and NOSQL. There are a lot of articles online already regarding this topic.<br />
This is about my experience with SQL and NOSQL.<br />
I primarily used Oracle, Mysql and some DB2. And I am mainly using Aurora SQL database and DynamoDB NOSQL nowadays.<br />
What I learned:<br />
Even though a lot of online talks mentioned using one single table approach with DynamoDB for microservices, it is not easy to do, especially if a microservice has relatively complex domain and goes through a lot of changes.<div> DynamoDB case insensitive search is not straightforward; it takes extra effort compared to SQL. When data needs to be encrypted and searched, be careful about the data management (for example, use lower case, use hash).<br />
DynamoDB throttling can be a pain depending on how you manage it, or whether your company is willing to pay more to avoid throttling.<br />
DynamoDB global secondary indexes could become expensive if you have too many.<br />
Some DynamoDB tricks mentioned online, for example, using some fake hashkey to enforce unique key constraints, using the same column to store many different types of data, could become a nightmare for application maintenance. Not many developers will be able to understand the code easily.<br />
DynamoDB transaction apis could provide great value to developers that come from the SQL world. But the transaction APIs are more expensive and relatively slow.<br />
Even with DynamoDB, you may still need to manage some kind of relationships between entities, which basically is similar to what you would do with SQL DB.<br />
DynamoDB is really a dummy map. Some things you normally can do with SQL DB, for example, create timestamp, SEQUENCE, becomes a burden in application code.<br />
DynamoDB stream is actually a great feature. But when integrating with lambdas, some duplication processing could happen in some cases.<br />
SQL database is not bad when it comes to handling large volume. Facebook mysql use is a good example. It takes good design, tuning, and maybe even customization.<br />
<br />
<br />
</div>Shaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.com0tag:blogger.com,1999:blog-728531761603831483.post-44178893062784555792017-12-01T09:41:00.002-08:002018-04-13T14:33:56.352-07:00Machine LearningMachine Learning<br />
<br />
<b>Purpose</b><br />
Machine Learning is to generalize.<br />
<br />
<b>Classic Problem</b><br />
Normal Programming: "Hello world"<br />
Machine Learning: MNIST<br />
<br />
<b>Approach</b><br />
Problems --> Tools--->Metrics (apply to all problems?)<br />
Data to generalize --> Use different algorithms --> Monitor performance of algorithms and adjust<br />
<br />
<b>Key Words</b><br />
Classification<br />
Discrete output<br />
Regression<br />
Continuous numeric output<br />
Clustering<br />
<br />
Gradient descent, Backpropagation, Cost function,<br />
Cross-entropy<br />
Any loss consisting of a negative log-likelihood between the empirical distribution<br />
defined by the training set and the probability distribution defined by model. For example,<br />
Mean Squared Error: cross-entropy between empirical distribution and a Gaussian model<br />
<br />
Activation function<br />
Step function<br />
discrete 0, 1<br />
Sigmoid function<br />
<br />
Tanh function<br />
<br />
Rectified Linear function (ReLU)<br />
<br />
Exponential linear unit (ELU)<br />
<br />
Training data set<br />
Train parameter<br />
Validation data set<br />
Tune Hyperparameter<br />
Test data set<br />
<br />
Bias, Variance<br />
Linked to capacity, underfitting, overfitting<br />
<br />
Closed-form solution<br />
<br />
Parameter<br />
Learned<br />
Weight, Bias<br />
HyperParameter<br />
Tuned<br />
Learning rate<br />
number of layers<br />
number of nueons each layer<br />
number of iterations<br />
<br />
Accuracy<br />
Sensitivity<br />
Specificity<br />
F1-score<br />
<br />
Kernel trick<br />
Maximum likelihood estimation<br />
Point estimate of variables<br />
<br />
Bayesian estimation<br />
Full distribution of variables<br />
<br />
Optimization<br />
Hill Climbing<br />
One step along axis one time<br />
Achieve Optimal solution for Convex problem<br />
Problems: local maxima, ridges and alleys, plateau<br />
Good for function complex and/or not differentiable<br />
<br />
Gradient Descent<br />
Vanishing/exploding gradients problems<br />
approaches to solve: He initialization, Batch Normalization<br />
<br />
Momentum<br />
<br />
AdaGrad<br />
<br />
RMSProp<br />
<br />
Adam<br />
<br />
Regularization<br />
Modification to ML algorithms, intending to reduce generalization error, not training error<br />
Example: weight decay for linear regression<br />
Early stoppping, L1, L2, Dropout, Max-Norm, Data Augmentation<br />
<br />
Generalize<br />
To have small gap between training error and test error<br />
Supervised Learning<br />
features + labels<br />
Nonprobabilistic SL<br />
K-Nearest Neighbor<br />
Decision Tree<br />
Unsupervised Learning<br />
features without labels<br />
Reinforcement Learning<br />
Learning by getting feedback from the environment<br />
<br />
Transformer:<br />
Modify or filter data before feeding it to learning algorithms<br />
Preprocessing<br />
Feature selection<br />
Feature extraction<br />
Dimension reduction (PCA, manifold learning)<br />
Kernel approximation<br />
<br />
Cross-validation schemes<br />
K-fold<br />
Stratified K-fold<br />
Leave-one-out (small amount of data)<br />
<br />
Dimension Reduction<br />
PCA<br />
KPCA<br />
LLE<br />
<br />
<b>Math behind ML</b><br />
<span class="mi" id="MathJax-Span-150" style="background-color: white; border: 0px; color: #2a2a2a; display: inline; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px; white-space: nowrap;">z<span style="border: 0px; display: inline-block; height: 1px; line-height: normal; margin: 0px; overflow: hidden; padding: 0px; position: static; transition: none; vertical-align: 0px; width: 0.002em;"></span></span><span class="mo" id="MathJax-Span-151" style="background-color: white; border: 0px; color: #2a2a2a; display: inline; font-family: "mathjax_main"; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px 0px 0px 0.297em; position: static; transition: none; vertical-align: 0px; white-space: nowrap;">=</span><span class="mi" id="MathJax-Span-152" style="background-color: white; border: 0px; color: #2a2a2a; display: inline; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px 0px 0px 0.297em; position: static; transition: none; vertical-align: 0px; white-space: nowrap;">w</span><span class="mi" id="MathJax-Span-153" style="background-color: white; border: 0px; color: #2a2a2a; display: inline; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px; white-space: nowrap;">x</span><span class="mo" id="MathJax-Span-154" style="background-color: white; border: 0px; color: #2a2a2a; display: inline; font-family: "mathjax_main"; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px 0px 0px 0.248em; position: static; transition: none; vertical-align: 0px; white-space: nowrap;">+</span><span class="mi" id="MathJax-Span-155" style="background-color: white; border: 0px; color: #2a2a2a; display: inline; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px 0px 0px 0.248em; position: static; transition: none; vertical-align: 0px; white-space: nowrap;">b</span><br />
<span class="mi" style="background-color: white; border: 0px; color: #2a2a2a; display: inline; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px 0px 0px 0.248em; position: static; transition: none; vertical-align: 0px; white-space: nowrap;"><span class="mi" id="MathJax-Span-862" style="border: 0px; display: inline; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;"> σ<span style="border: 0px; display: inline-block; height: 1px; line-height: normal; margin: 0px; overflow: hidden; padding: 0px; position: static; transition: none; vertical-align: 0px; width: 0.002em;"></span></span><span class="mo" id="MathJax-Span-863" style="border: 0px; display: inline; font-family: "mathjax_main"; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;">(</span><span class="mi" id="MathJax-Span-864" style="border: 0px; display: inline; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;">z<span style="border: 0px; display: inline-block; height: 1px; line-height: normal; margin: 0px; overflow: hidden; padding: 0px; position: static; transition: none; vertical-align: 0px; width: 0.002em;"></span></span><span class="mo" id="MathJax-Span-865" style="border: 0px; display: inline; font-family: "mathjax_main"; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;">)</span><span class="mo" id="MathJax-Span-866" style="border: 0px; display: inline; font-family: "mathjax_main"; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px 0px 0px 0.297em; position: static; transition: none; vertical-align: 0px;">=</span><span class="mn" id="MathJax-Span-867" style="border: 0px; display: inline; font-family: "mathjax_main"; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px 0px 0px 0.297em; position: static; transition: none; vertical-align: 0px;">1</span><span class="texatom" id="MathJax-Span-868" style="border: 0px; display: inline; font-family: "georgia" , "times new roman" , serif; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;"><span class="mrow" id="MathJax-Span-869" style="border: 0px; display: inline; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;"><span class="mo" id="MathJax-Span-870" style="border: 0px; display: inline; font-family: "mathjax_main"; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;">/</span></span></span><span class="mo" id="MathJax-Span-871" style="border: 0px; display: inline; font-family: "mathjax_main"; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;">(</span><span class="mn" id="MathJax-Span-872" style="border: 0px; display: inline; font-family: "mathjax_main"; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;">1</span><span class="mo" id="MathJax-Span-873" style="border: 0px; display: inline; font-family: "mathjax_main"; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px 0px 0px 0.248em; position: static; transition: none; vertical-align: 0px;">+</span><span class="msubsup" id="MathJax-Span-874" style="border: 0px; display: inline; font-family: "georgia" , "times new roman" , serif; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px 0px 0px 0.248em; position: static; transition: none; vertical-align: 0px;"><span style="border: 0px; display: inline-block; height: 0px; line-height: normal; margin: 0px; padding: 0px; position: relative; transition: none; vertical-align: 0px; width: 1.424em;"><span style="border: 0px; clip: rect(3.434em 1000.44em 4.169em -999.998em); left: 0em; line-height: normal; margin: 0px; padding: 0px; position: absolute; top: -4.017em; transition: none; vertical-align: 0px;"><span class="mi" id="MathJax-Span-875" style="border: 0px; display: inline; font-family: MathJax_Math-italic; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;">e</span><span style="border: 0px; display: inline-block; height: 4.022em; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px; width: 0px;"></span></span><span style="border: 0px; left: 0.493em; line-height: normal; margin: 0px; padding: 0px; position: absolute; top: -4.36em; transition: none; vertical-align: 0px;"><span class="texatom" id="MathJax-Span-876" style="border: 0px; display: inline; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;"><span class="mrow" id="MathJax-Span-877" style="border: 0px; display: inline; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;"><span class="mo" id="MathJax-Span-878" style="border: 0px; display: inline; font-family: "mathjax_main"; font-size: 14.4228px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;">−</span><span class="mi" id="MathJax-Span-879" style="border: 0px; display: inline; font-family: MathJax_Math-italic; font-size: 14.4228px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;">z<span style="border: 0px; display: inline-block; height: 1px; line-height: normal; margin: 0px; overflow: hidden; padding: 0px; position: static; transition: none; vertical-align: 0px; width: 0.002em;"></span></span></span></span><span style="border: 0px; display: inline-block; height: 4.022em; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px; width: 0px;"></span></span></span></span><span class="mo" id="MathJax-Span-880" style="border: 0px; display: inline; font-family: "mathjax_main"; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;">)</span></span><br />
<span class="mi" style="background-color: white; border: 0px; color: #2a2a2a; display: inline; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px 0px 0px 0.248em; position: static; transition: none; vertical-align: 0px; white-space: nowrap;"><span class="mo" style="border: 0px; display: inline; font-family: "mathjax_main"; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none; vertical-align: 0px;"> ...</span></span><br />
<span class="mi" style="background-color: white; border: 0px; color: #2a2a2a; display: inline; font-size: 20.4px; line-height: normal; margin: 0px; padding: 0px 0px 0px 0.248em; position: static; transition: none; vertical-align: 0px; white-space: nowrap;"><br /></span>
<br />
<b>Concepts</b><br />
Model--Train--Evaluate--Predict<br />
Classification, Regression, Clustering, Dimension deduction<br />
<br />
<b>Algorithms</b><br />
Linear Regression<br />
Find optimal weights by solving normal equations<br />
<br />
Logistic Regression<br />
No closed-form solution. Maximizing the log-likelihood, or minimizing the negative log-likelihood using gradient descent.<br />
<br />
Neural Network<br />
RNN (Recurrent Neural Network)<br />
CNN (Convolutional Neural Network)<br />
<br />
Decision Tree<br />
<br />
Identification Tree<br />
<br />
Naive Bayes<br />
Features independent of each other<br />
Conditional Probability Model<br />
Highly scalable, only requires small amount of training data<br />
Linear Performance Time<br />
Generally outperformed by other algorithms, SVM...<br />
<br />
Support Vector Machines<br />
For both classification and regression<br />
Widest street to separate instances of different classes<br />
<br />
Random Forest<br />
Decision Tree ensemble<br />
<br />
<b>Test Methodologies</b><br />
Leave one out LOO<br />
for small amount of data<br />
<br />
Data split (80/20)<br />
<br />
<b>Practical Guidelines for DNN</b><br />
Initialization He<br />
Activation ELU<br />
Normalization Batch Normalization<br />
Regularization Dropout<br />
Optimizer Adam<br />
Learning Rate Schedule None<br />
<br />
<b>Software</b><br />
Tensorflow, Scikit-learn<br />
Spark MLLib, Spark ML, Weka,<br />
<br />
<br />
<b>Use cases</b><br />
Linear Regression<br />
House size---> House price in a community<br />
<br />
Naive Bayes<br />
Document classification: separate legitimate emails from spam emails<br />
For example, based on key words: cheap, free<br />
<br />
<b>Questions</b><br />
When to use which algorithm(s)?<br />
<br />
<b>Classic Applications</b><br />
Alphago vs Lee Sedol<br />
https://en.wikipedia.org/wiki/AlphaGo_versus_Lee_Sedol<br />
<br />
Autonomous Car<br />
<br />
Netflix movie recommendations<br />
<br />
Image recognitions<br />
<br />
Natural language processing<br />
<br />
<b>Summary</b><br />
No ML algorithm is universally better than any other algorithm.<br />
Understand data distribution, and pick proper algorithm(s).<br />
<br />
<b>References</b><br />
<br />
Books<br />
(One of my favorite books, highly recommended)<br />
<a href="https://www.amazon.com/Hands-Machine-Learning-Scikit-Learn-TensorFlow/dp/1491962291/ref=sr_1_1?s=books&ie=UTF8&qid=1516719347&sr=1-1&keywords=Hands-On+Machine+Learning+with+Scikit-Learn+and+TensorFlow%3A+Concepts%2C+Tools%2C+and+Techniques+to+Build+Intelligent+Systems" target="_blank">Hands-On Machine Learning with Scikit-Learn and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems</a><br />
<br />
<a href="https://sites.ualberta.ca/~szepesva/papers/RLAlgsInMDPs.pdf" target="_blank">Algorithms for Reinforcement Learning</a><br />
<br />
<a href="http://www.deeplearningbook.org/" target="_blank">Deep Learning (Adaptive Computation and Machine Learning series)</a><br />
<br />
<a href="http://neuralnetworksanddeeplearning.com/" target="_blank">http://neuralnetworksanddeeplearning.com/</a><br />
<br />
<a href="https://www.tensorflow.org/" target="_blank">TensorFlow</a><br />
<br />
<a href="http://scikit-learn.org/" target="_blank">scikit-learn</a><br />
<br />
<a href="https://www.kaggle.com/">https://www.kaggle.com/</a><br />
<br />
<a href="https://www.youtube.com/watch?v=2pWv7GOvuf0" target="_blank">Reinforcement Learning - David Silver</a><br />
<br />
<a href="http://www.wildml.com/" target="_blank">http://www.wildml.com/</a><br />
<br />
<a href="https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-034-artificial-intelligence-fall-2010/" target="_blank">https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-034-artificial-intelligence-fall-2010/</a><br />
<br />
Machine learning series from Luis Serrano (Very good explanations for beginners)<br />
<a href="https://www.youtube.com/watch?v=aDW44NPhNw0" target="_blank">https://www.youtube.com/watch?v=aDW44NPhNw0</a><br />
<a href="https://www.youtube.com/watch?v=BR9h47Jtqyw&t=24s" target="_blank">https://www.youtube.com/watch?v=BR9h47Jtqyw&t=24s</a><br />
<a href="https://www.youtube.com/watch?v=2-Ol7ZB0MmU&t=7s" target="_blank">https://www.youtube.com/watch?v=2-Ol7ZB0MmU&t=7s</a><br />
<a href="https://www.youtube.com/watch?v=IpGxLWOIZy4" target="_blank">https://www.youtube.com/watch?v=IpGxLWOIZy4</a><br />
<br />
<a href="http://scikit-learn.org/stable/tutorial/machine_learning_map/" target="_blank">http://scikit-learn.org/stable/tutorial/machine_learning_map/</a><br />
<br />
<a href="https://blogs.sas.com/content/subconsciousmusings/2017/04/12/machine-learning-algorithm-use/" target="_blank">https://blogs.sas.com/content/subconsciousmusings/2017/04/12/machine-learning-algorithm-use/</a><br />
<br />
<a href="https://s3.amazonaws.com/assets.datacamp.com/blog_assets/PythonForDataScience.pdf">https://s3.amazonaws.com/assets.datacamp.com/blog_assets/PythonForDataScience.pdf</a><br />
<br />
<a href="https://s3.amazonaws.com/assets.datacamp.com/blog_assets/Scikit_Learn_Cheat_Sheet_Python.pdf">https://s3.amazonaws.com/assets.datacamp.com/blog_assets/Scikit_Learn_Cheat_Sheet_Python.pdf</a><br />
<br />
<a href="https://storage.googleapis.com/deepmind-media/alphago/AlphaGoNaturePaper.pdf">https://storage.googleapis.com/deepmind-media/alphago/AlphaGoNaturePaper.pdf</a><br />
<br />
(AWS machine learning service)<br />
<a href="https://aws.amazon.com/blogs/aws/sagemaker/">https://aws.amazon.com/blogs/aws/sagemaker/</a><br />
<br />
(Spark MLlib example)<br />
<a href="https://stanford.edu/~rezab/sparkworkshop/slides/xiangrui.pdf">https://stanford.edu/~rezab/sparkworkshop/slides/xiangrui.pdf</a><br />
<br />
<a href="https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-0002-introduction-to-computational-thinking-and-data-science-fall-2016/" target="_blank">https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-0002-introduction-to-computational-thinking-and-data-science-fall-2016/</a><br />
<br />
<a href="https://biomedical-engineering-online.biomedcentral.com/articles/10.1186/s12938-017-0378-z">https://biomedical-engineering-online.biomedcentral.com/articles/10.1186/s12938-017-0378-z</a><br />
<br />
<a href="https://iknowfirst.com/rsar-machine-learning-trading-stock-market-and-chaos">https://iknowfirst.com/rsar-machine-learning-trading-stock-market-and-chaos</a><br />
<br />
<a href="https://www.nature.com/articles/nature24270.epdf?author_access_token=VJXbVjaSHxFoctQQ4p2k4tRgN0jAjWel9jnR3ZoTv0PVW4gB86EEpGqTRDtpIz-2rmo8-KG06gqVobU5NSCFeHILHcVFUeMsbvwS-lxjqQGg98faovwjxeTUgZAUMnRQ" target="_blank">Mastering the game of Go without human knowledge</a><br />
<br />
<br />
<br />Shaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.com1tag:blogger.com,1999:blog-728531761603831483.post-59106493173118415912017-01-31T06:54:00.000-08:002017-01-31T06:54:56.942-08:00String valueOf() pitfallsWhat will the console output of this program?<br />
<br />
<br />
public class TestStringValueOf {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public static void main(String[] args) {<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>testStringValueOfChar();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<br />
public static void testStringValueOfChar() {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>char a = 'a';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String str1 = String.valueOf(a);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String str2 = String.valueOf(a);<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.out.println("char comparison:" + (str1 == str2));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>double d = 12.3d;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String str3 = String.valueOf(d);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String str4 = String.valueOf(d);<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.out.println("double comparison:" + (str3 == str4));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>boolean b = false;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String str5 = String.valueOf(b);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String str6 = String.valueOf(b);<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.out.println("boolean comparison:" + (str5 == str6));<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Object o = null;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String str7 = String.valueOf(o);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String str8 = String.valueOf(o);<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.out.println("Object null comparison:" + (str7 == str8));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Object notNull = new Object();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String str9 = String.valueOf(notNull);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String str10 = String.valueOf(notNull);<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.out.println("Object Not null comparison:" + (str9 == str10));<br />
}<br />
}<br />
<br />
see the end of this article for the output.<br />
<br />
Overall, the string comparison should use 'equals' no matter how String objects were created.<br />
<br />
<br />
-------console output----------<br />
<br />
char comparison:false<br />
double comparison:false<br />
<b>boolean comparison:true</b><br />
<b>Object null comparison:true</b><br />
Object Not null comparison:false<br />
<div>
<br /></div>
<br />Shaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.com1tag:blogger.com,1999:blog-728531761603831483.post-50583403591646135052016-07-18T09:32:00.000-07:002016-07-18T09:32:51.870-07:00Spring MVC UTF-8Key points<br />
<br />
web.xml:<br />
<filter> <br />
<filter-name>encodingFilter</filter-name> <br />
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <br />
<init-param> <br />
<param-name>encoding</param-name> <br />
<param-value>UTF-8</param-value> <br />
</init-param> <br />
<init-param> <br />
<param-name>forceEncoding</param-name> <br />
<param-value>true</param-value> <br />
</init-param> <br />
</filter> <br />
<filter-mapping> <br />
<filter-name>encodingFilter</filter-name> <br />
<url-pattern>/*</url-pattern> <br />
</filter-mapping><br />
<br />
<br />
Maven pom.xml:<br />
<properties><br />
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><br />
...<br />
</properties><br />
<br />
JSP:<br />
<%@ page language="java" pageEncoding="UTF-8"%><br />
<%@ page contentType="text/html;charset=UTF-8" %><br />
<br />
<br />Shaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.com0tag:blogger.com,1999:blog-728531761603831483.post-72447651541854006282016-06-17T14:19:00.000-07:002016-06-17T14:19:31.154-07:00Compile xsl files and store in cache to improve XSLT performance<br />Common code found online to do XSLT transformation. (removed non essential pieces for brevity)<br /><br />------------------<div>
TransformerFactory transformerFactory = TransformerFactory.newInstance();<br />Transformer transformer =
transformerFactory.newTransformer(new StreamSource(new File(xsltPath)));<br />transformer.transform(new StreamSource(new File(sourceFilePath)),
new StreamResult(new File(resultPath)));<br /><pre class="java" name="code" style="background-color: white; color: #222222; font-size: 13.2px; line-height: 18.48px;">----------------</pre>
<pre class="java" name="code" style="background-color: white; color: #222222; font-size: 13.2px; line-height: 18.48px;">
</pre>
<pre class="java" name="code" style="background-color: white; color: #222222; line-height: 18.48px;"><span style="font-size: large;"><b>The code works. But if a xslt file is relatively big and </b></span></pre>
<pre class="java" name="code" style="background-color: white; color: #222222; line-height: 18.48px;"><span style="font-size: large;"><b>needs to be used over and over again to transform </b></span></pre>
<pre class="java" name="code" style="background-color: white; color: #222222; line-height: 18.48px;"><b><span style="font-size: large;">a lot of files, </span><span style="font-size: large; line-height: 18.48px;">for example, in the batch mode, </span></b></pre>
<pre class="java" name="code" style="background-color: white; color: #222222; line-height: 18.48px;"><span style="font-size: large; line-height: 18.48px;"><b>it may not perform well. </b></span></pre>
<br />
<br />
The following shows a way to cache the compiled version of an xsl file, which is a '<b>Templates' object</b>. This object <b>is thread safe</b>.<br />
<br />
Code snippet to cache the 'Templates' object.<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>static final Map<String, Templates> cacheTemplates = new ConcurrentHashMap<String, Templates>();<br />
<div>
<br /></div>
<div>
static TransformerFactory transformFactory = null;</div>
<div>
<br /></div>
<div>
static {</div>
<div>
init();</div>
<div>
}</div>
<div>
<br /></div>
<div>
private static void init() {</div>
<div>
try {</div>
<div>
transformFactory =TransformerFactory.newInstance();</div>
<div>
}</div>
<div>
catch(Exception e) {</div>
<div>
throw new RuntimeException(e);</div>
<div>
}</div>
<div>
}</div>
<div>
<br /></div>
public static void cacheCompiled( String xsl) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>File file = null;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>StreamSource source= null;<br />
Templates templates = null;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>try {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>file = new File( xsl);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>source = new StreamSource(file);<br />
<b> templates = transformFactory.newTemplates(source); //create this once for a file, save in a cache.</b><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><b>cacheTemplates .put(xsl, templates );</b><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} catch (Exception e) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>throw new RuntimeException(e);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} finally {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
The above 'templates' object is basically a coompiled version of the original xsl file. If the original file is relatively big, for example, 20KB, it takes more than 2 seconds on my local machine to transform a small file. <b>Without caching</b> the templates, it takes more than <b>2 seconds </b>every time. <b>With caching</b>, it <b>takes about 0.1 seconds</b> for every transformation after the first time.<br />
<br />
<br /><br />The basic code is like this:<br /><br />//get the Templates object from cache based on the xsl file name, then get a Transformer object<br /><br />Transformer transformer = templates.newTransformer();<br /><br />transformer.transform(new StreamSource(new File(sourceFilePath)),<br /> new StreamResult(new File(resultPath)));<div>
<br /><b>The 'transformer' object mentioned above is not thread safe.</b></div>
</div>
<div>
<b><br /></b></div>
<div>
The SAXON parser seems becoming more popular, and the Xalan parser seems fading away.</div>
<div>
<br /></div>
<div>
The home edition of the SAXON parser, which is free, may be good enough for a lot of applications.</div>
<div>
<b><br /></b></div>
Shaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.com0tag:blogger.com,1999:blog-728531761603831483.post-15056930817487995352013-11-15T13:50:00.001-08:002013-11-15T13:50:50.718-08:00First impressions on open source ESBsUsed commercial ESB and BPMs for a couple of years, recently had a chance to evaluate some open source ESBs.<br />
<br />
WSO2: not easy to use, had difficulty even making the sample projects to work. No DataMapper tool, which is a big no-no to my projects.<br />
<br />
Mulesoft ESB: Nice documentation, instructions easy to follow, sample projects can be built and run in a couple of minutes, nice DataMapper tool in the 3.4 version. Have not had a chance to build a relatively complex application using this. Not sure whether the community edition is good enough to be used in the Production.<br />
<br />
<br />Shaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.com0tag:blogger.com,1999:blog-728531761603831483.post-76848891604159860542013-09-02T08:22:00.000-07:002013-09-02T08:22:58.747-07:00String getBytes could lead to difficult bugsIf you execute the following function, what do you think should be the size of the 'def' byte array?<br />
<br />
The logic is really simple: an input as byte array that have two elements, then create a string out of this with 'UTF-8' encoding, then create another byte array using this string with the same UTF-8 encoding.<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public static void testStringUTF8() {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>byte[] abc = new byte[2];<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>abc[0] = 31;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>abc[1] = -117;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>try {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String stringAbc = new String(abc, "UTF-8");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>byte[] def = stringAbc.getBytes("UTF-8");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (def != null) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.out.println("size of output byte array:" + def.length); //print the array size<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.out.println(def[1]); //print the second element of the output byte array<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.out.println(abc[1]); //print the second element of the input byte array<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} catch (Exception e) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>e.printStackTrace();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
---------------<br />
<br />Shaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.com1tag:blogger.com,1999:blog-728531761603831483.post-52122356157272133952012-04-11T12:09:00.000-07:002012-04-11T12:09:46.547-07:00How to invoke local EJB session beans in WebLogicSometimes you may have a need to invoke a LOCAL EJB session beans in a normal java class, for example, Business Delegate class, you can use ServiceLocator to locate a local EJB session bean proxy by JNDI name. Even though it is relatively easy to do so for a REMOTE EJB session bean by using the value of 'name' or 'mappedName' in the bean class definition, it is a little tricky for LOCAL session beans.<br />
<br />
Here is what you need to do.<br />
<br />
For exampe:<br />
<br />
Here is an interface:<br />
<br />
package com.play;<br />
<br />
@Local<br />
public interface PlayFacadeInf {<br />
public void play(String var);<br />
}<br />
<br />
<br />
Here is the implementation bean class.<br />
<br />
package com.play; <br />
<br />
@Stateless<br />
public class PlayFacadeImpl implements PlayFacadeInf {<br />
public void play(String var) {<br />
//...do somthing<br />
}<br />
}<br />
<br />
<br />
Here is the part of the ejb-jar.xml<br />
<br />
<br />
display-name>myEJB </display-name><br />
<enterprise-beans><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><session><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><ejb-name> PlayFacadeImpl</ejb-name><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><ejb-class>com.play.PlayFacadeImpl</ejb-class><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><ejb-local-ref><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><ejb-ref-name><b>ejb/PlayFacadeInf</b></ejb-ref-name><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><ejb-ref-type>Session</ejb-ref-type><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><local>com.play.PlayFacadeInf</local><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span></ejb-local-ref><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span></session><br />
</enterprise-beans> <br />
<br />
Here is part of web.xml<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><ejb-local-ref><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><ejb-ref-name><b>ejb/PlayFacadeInf</b></ejb-ref-name><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><ejb-ref-type>Session</ejb-ref-type><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><local>com.play.PlayFacadeInf</local><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span></ejb-local-ref><br />
<br />
Here is part of the ServiceLocator.java<br />
<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private static InitialContext ctx = null;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>static {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>try {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>ctx = new InitialContext();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>catch (NamingException e) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//... throw some exception<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private static InitialContext getInitialContext() throws NamingException{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return ctx;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public static PlayFacadeInf getPlayFacade() throws NamingException {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> PlayFacadeInf playFacadeInf = null;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> playFacadeInf = ( PlayFacadeInf ) <br />
ServiceLocator.getInitialContext().lookup("<b>java:/comp/env/ejb/PlayFacadeInf</b>");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return playFacadeInf;<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
Then any normal java class can use the ServiceLocator to get hold of the local ejb session bean proxy.Shaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.com2tag:blogger.com,1999:blog-728531761603831483.post-41299443103737083242011-02-13T10:42:00.000-08:002011-02-13T10:42:42.785-08:00JPA NoResultException marks transaction rollback in WebLogic 10.3.2<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>ZH-CN</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> <w:UseFELayout/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" Priority="39" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" Name="toc 9"/> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/> <w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> <w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/> <w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style> <![endif]--> <br />
<div class="MsoNormal"><span style="font-size: 10pt; line-height: 115%;">The weblogic 10.3.2 server comes with two jpa implementations: eclipselink (org.eclipse.persistence_1.0.0.0_1-2-0.jar) and openjpa (org.apache.openjpa_1.0.1.0_1-1-1-SNAPSHOT.jar). <span> </span>By default, it uses the openjpa. But you can add “<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>” to the persistence.xml to use the eclipselink implementation. </span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-size: 10pt; line-height: 115%;">Both implementations do not handle “<b>NoResultException</b>” properly. The “NoResultException”thrown in a transaction would mark the transaction as <b>rolledback</b>, which violates the JPA specification.</span></div><div class="MsoNormal"><br />
</div><div style="border-color: -moz-use-text-color -moz-use-text-color windowtext; border-style: none none solid; border-width: medium medium 1pt; padding: 0in 0in 1pt;"> <div class="MsoNormal" style="border: medium none; padding: 0in;"><span style="font-size: 10pt; line-height: 115%;">Some sample code (using EJB 3) is as follows:</span></div></div><div class="MsoNoSpacing"><span style="font-size: 8pt;">@Stateless</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;">public class FacadeImpl implements FacadeInf {</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span>@EJB</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span>DAOInf dAOInf;</span></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span>public void findOrCreate(Long [] addressIds, PersonAddressData personAddressData) {</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span>..........</span></div><div class="MsoNoSpacing" style="margin-left: 0.5in; text-indent: 0.5in;"><span style="font-size: 8pt;">for (Long addressId: addressIds) {</span></div><div class="MsoNoSpacing" style="margin-left: 1in; text-indent: 0.5in;"><span style="font-size: 8pt;">try {</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span><span> </span>dAOInf.findByAddress(addressId);</span></div><div class="MsoNoSpacing" style="margin-left: 1in; text-indent: 0.5in;"><span style="font-size: 8pt;">}</span></div><div class="MsoNoSpacing" style="margin-left: 1in; text-indent: 0.5in;"><span style="font-size: 8pt;">catch(Exception e) { //find failed, try to create something</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span><span> </span>....createInfo(personAddressData);</span></div><div class="MsoNoSpacing" style="margin-left: 1in; text-indent: 0.5in;"><span style="font-size: 8pt;">}</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span>}</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span>}</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;">}</span></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><span style="font-size: 8pt;">@Stateless</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;">public class DAOImpl implements DAOInf {</span></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span>@PersistenceContext(unitName = "SampleJPA")</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span>EntityManager em;</span></div><div class="MsoNoSpacing"><br />
</div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span>//@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span>public Person findByAddress(Long addressId) {</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span><span> </span>return (Person)em.createNamedQuery("someNamedQuery").getSingleResult();</span></div><div class="MsoNoSpacing"><span style="font-size: 8pt;"><span> </span>}</span></div><div style="border-color: -moz-use-text-color -moz-use-text-color windowtext; border-style: none none solid; border-width: medium medium 1pt; padding: 0in 0in 1pt;"> <div class="MsoNoSpacing" style="border: medium none; padding: 0in;"><span style="font-size: 8pt;">}</span></div></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-size: 10pt; line-height: 115%;">In the above snippet,<span> </span>if in the “for loop”, one invocation of “findByAddress” threw the “NoResultException”, the active transaction would be marked as rolledback, the “createInfo” in the “catch” block would not be able to accomplish anything. But if “</span><span style="font-size: 8pt; line-height: 115%;">@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)</span><span style="font-size: 10pt; line-height: 115%;">” <span style="display: none;">n the above snippet, if specification.edbackdd pselinkLogic 10.3.2</span></span></div><div class="MsoNormal"><span style="font-size: 10pt; line-height: 115%;">were not commented out, which means the “findByAddress” would run in a “NON transaction” context, in this case, even if the “find” function failed, the transaction could still continue, so the “createInfo” could be executed properly.</span></div><div class="MsoNormal"><br />
</div><span style="font-family: "Calibri","sans-serif"; font-size: 10pt; line-height: 115%;">Most find functions (except findByPrimaryKey) in session bean DAOs should be marked as “Transaction NOT SUPPORTED” (@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)).<br />
<br />
</span>Shaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.com0tag:blogger.com,1999:blog-728531761603831483.post-70315602358741902202010-11-17T07:48:00.000-08:002010-11-17T07:48:36.964-08:00How to Fix Java POJO Annotations<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>ZH-CN</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> <w:UseFELayout/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" Priority="39" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" Name="toc 9"/> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/> <w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> <w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/> <w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style> <![endif]--> <br />
<div style="border-color: -moz-use-text-color -moz-use-text-color windowtext; border-style: none none solid; border-width: medium medium 1pt; padding: 0in 0in 1pt;"> <div class="MsoNormal" style="border: medium none; padding: 0in;">POJO and Annotation are a big part of the java world nowadays.<span> </span>Spring, EJB, JPA, Servlet, <span> </span>JSF and other technologies are using annotated POJOs. The traditional definition is that a POJO is an ordinary Java Object, which means it has no dependency on any framework or container.<span> </span> </div><div class="MsoNormal" style="border: medium none; padding: 0in;"><br />
</div><div class="MsoNormal" style="border: medium none; padding: 0in;">But take a look at the following example:</div></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><b><span style="color: #7f0055; font-family: "Courier New"; font-size: 10pt;">import</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> javax.ejb.*;</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: #646464; font-family: "Courier New"; font-size: 10pt;">@Stateless</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">(name = </span><span style="color: #2a00ff; font-family: "Courier New"; font-size: 10pt;">"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">Test11</span><span style="color: #2a00ff; font-family: "Courier New"; font-size: 10pt;">"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">, mappedName = </span><span style="color: #2a00ff; font-family: "Courier New"; font-size: 10pt;">"ejb.abc"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">)</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><b><span style="color: #7f0055; font-family: "Courier New"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "Courier New"; font-size: 10pt;">class</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> Test11Bean </span><b><span style="color: #7f0055; font-family: "Courier New"; font-size: 10pt;">implements</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> Test11{</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><span> </span></span><b><span style="color: #7f0055; font-family: "Courier New"; font-size: 10pt;">private</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "Courier New"; font-size: 10pt;">static</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "Courier New"; font-size: 10pt;">final</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "Courier New"; font-size: 10pt;">long</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: "Courier New"; font-size: 10pt;">serialVersionUID</span></i><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> = -128L;</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><span> </span></span><span style="color: #646464; font-family: "Courier New"; font-size: 10pt;">@EJB</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><span> </span></span><b><span style="color: #7f0055; font-family: "Courier New"; font-size: 10pt;">protected</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> TestSb </span><span style="color: #0000c0; font-family: "Courier New"; font-size: 10pt;">testsb</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">;</span><span style="font-family: "Courier New"; font-size: 10pt;"></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt; line-height: 115%;"><span> </span></span><b><span style="color: #7f0055; font-family: "Courier New"; font-size: 10pt; line-height: 115%;">public</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt; line-height: 115%;"> Double getCost(String name, String expedite) {</span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt; line-height: 115%;"><span> </span>return 0.0;</span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt; line-height: 115%;">}</span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt; line-height: 115%;">….</span></div><div style="border-color: -moz-use-text-color -moz-use-text-color windowtext; border-style: none none solid; border-width: medium medium 1pt; padding: 0in 0in 1pt;"> <div class="MsoNormal" style="border: medium none; padding: 0in;"><span style="color: black; font-family: "Courier New"; font-size: 10pt; line-height: 115%;">}</span></div></div><div class="MsoNormal">As we can see, without ejb related jar file in the classpath, this code would not compile at all. If we want to use this in a weblogic container eventually, we may add “TransactionTimeoutSeconds” and other weblogic kodo related annotations.<span> </span>In this case, we need to have vendor-specific jar files in order to compile this class.<span> </span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span> </span>I think some changes can be done to make it a traditionally-defined POJO. <span> </span>Here is what I would do:</div><div class="MsoNormal">I would <b>change the “import” to “@import”</b> (or maybe another new keyword.) This will serve as a hint during the compilation, deployment and run times. During different stages (compilation, deployment and run), depending on whether the related jar files are in the classpath, different actions can be taken to generate different artifacts.</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b>What are the benefits of doing this?</b></div><div class="MsoListParagraphCxSpFirst" style="text-indent: -0.25in;"><span><span>1.<span style="font: 7pt "Times New Roman";"> </span></span></span>Code can be reused more often.<span> </span>Sometimes I want to use a JPA POJO entity class as a pure simple bean (like a data transfer object) in another project,<span> </span>it would be possible if it did not have dependency on some jars.</div><div class="MsoListParagraphCxSpLast" style="text-indent: -0.25in;"><span><span>2.<span style="font: 7pt "Times New Roman";"> </span></span></span>Could make the testing easier. </div>Shaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.com2tag:blogger.com,1999:blog-728531761603831483.post-1220684107124238562010-10-14T10:17:00.000-07:002016-07-18T09:37:12.791-07:00How to use EJB 3 timer in a weblogic 10 cluster environment<div class="MsoNormal">
</div>
<div class="MsoNormal">
Although there are some articles talking about EJB 3 timers or job schedulers , we were not able to find any detailed instructions on how to make EJB 3 timer work in a weblogic cluster. In this article we will go through a sample project to show how EJB 3 timers are used in a weblogic cluster. The sample project will create two recurring timers, the first recurring timer will periodically print out some simple information, the second recurring timer will create a couple of one-timer timers, each of which will print out some information. In this article, we will show you how to use weblogic admin console to configure the cluster, how the application uses the related configuration from the console and how to invoke timers, also explain what problems we faced and how we solved them.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Environment: </b></div>
<div class="MsoNormal">
web logic server 10.3.2, oracle database 11gR1, Eclipse Helios</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Code:</b></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">Timer1SessionBeanLocal: local interface for creating timer</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@Local</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">interface</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer1SessionBeanLocal {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">void</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> createTimer();</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">}</span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">Timer1SessionBean: a recurring timer that prints out something</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@Stateless</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">class</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer1SessionBean </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">implements</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer1SessionBeanLocal {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@Resource</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> TimerService </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timerService</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">;</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer1SessionBean() {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">void</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> createTimer() {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timerService</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">.createTimer(</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> 60000,</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> 60000, </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">null</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;">);</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@Timeout</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">void</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> timeout(Timer arg0) {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">out</span></i><span style="color: black; font-family: "courier new"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "courier new"; font-size: 10pt;">"recurring timer1 : "</span><span style="color: black; font-family: "courier new"; font-size: 10pt;"> + </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">new</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Date());</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">}</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">Timer2SessionBean: a recurring timer that creates a bunch of one-time timers,al</span>so the number of one-time timers created is roughly based on the maximum allowed number of active timers minus the number of active timers at that time.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@Stateless</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">class</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer2SessionBean </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">implements</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer2SessionBeanLocal {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@Resource</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> TimerService </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timerService</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">;</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@EJB</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer3SessionBeanLocal </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timer3Bean</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">;</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer2SessionBean() {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">void</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> createTimer() {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timerService</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">.createTimer(120000, 300000, </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">null</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;">);</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@Timeout</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">void</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> timeout(Timer arg0) {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">out</span></i><span style="color: black; font-family: "courier new"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "courier new"; font-size: 10pt;">"recurring timer2 : "</span><span style="color: black; font-family: "courier new"; font-size: 10pt;"> + </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">new</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Date());</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: "courier new"; font-size: 10pt;">// used to control the total number of threads running in the <u>app</u></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: "courier new"; font-size: 10pt;">// use 10 as maximum in this example.</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">int</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> numberOfActiveTimers = </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timer3Bean</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">.getCountOfActiveTimers();</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">if</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> (numberOfActiveTimers < 10) {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">int</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> toCreateNum = 10 - numberOfActiveTimers;</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">for</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> (</span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">int</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> i = 0; i < toCreateNum; i++) {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer3Info info = </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">new</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer3Info();</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: "courier new"; font-size: 10pt;">// set start delays to be 30,60,90... seconds</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> info.setDelay(30000 * (i + 1)); </span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timer3Bean</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">.createTimer(info);</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">out</span></i><span style="color: black; font-family: "courier new"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "courier new"; font-size: 10pt;">"Exit timeout in timer2"</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">);</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">}</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">Timer3SessionBean: one-time timer created by another timer, provides the number of active timers for this bean, and prints out something.</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@Stateless</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">class</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer3SessionBean </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">implements</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer3SessionBeanLocal {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@Resource</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> TimerService </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timerService</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">;</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer3SessionBean() {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">void</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> createTimer(Timer3Info timerInfo) {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timerService</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">.createTimer(timerInfo.getDelay(), </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">null</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;">);</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@Timeout</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">void</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> timeout(Timer arg0) {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">out</span></i><span style="color: black; font-family: "courier new"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "courier new"; font-size: 10pt;">"one-time timer3 : "</span><span style="color: black; font-family: "courier new"; font-size: 10pt;"> + </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">new</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Date());</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;">/**</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> * </span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> * </span><b><span style="color: #7f9fbf; font-family: "courier new"; font-size: 10pt;">@return</span></b><span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> the number of active timers</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> */</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">int</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> getCountOfActiveTimers(){</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">int</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> retVal = 0;</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">try</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: "courier new"; font-size: 10pt;">//In rare occasions, could throw NullPointerException //because of a bug in <u>weblogic</u></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@SuppressWarnings</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">(</span><span style="color: #2a00ff; font-family: "courier new"; font-size: 10pt;">"unchecked"</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">)</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> Collection<Timer> timersCol = </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timerService</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">.getTimers(); </span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">if</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> (timersCol != </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">null</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;">)</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> retVal = timersCol.size();</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> } </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">catch</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> (Exception e) {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: "courier new"; font-size: 10pt;">//if it failed, use the maximum (10 in this example), so no //new timers can be created</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> retVal = 10;</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">return</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> retVal;</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">}</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">TestTimerCreateServlet: used to create recurring timers.</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">class</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> TestTimerCreateServlet </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">extends</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> HttpServlet {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">private</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">static</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">final</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">long</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">serialVersionUID</span></i><span style="color: black; font-family: "courier new"; font-size: 10pt;"> = 1L;</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@EJB</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer1SessionBeanLocal </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timer1</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">;</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@EJB</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer2SessionBeanLocal </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timer2</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">;</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;">/**</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> * </span><b><span style="color: #7f9fbf; font-family: "courier new"; font-size: 10pt;">@see</span></b><span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> HttpServlet#HttpServlet()</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> */</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">public</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> TestTimerCreateServlet() {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">super</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;">();</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;">/**</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> * </span><b><span style="color: #7f9fbf; font-family: "courier new"; font-size: 10pt;">@see</span></b><span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> HttpServlet#doGet(HttpServletRequest request, HttpServletResponse</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> * response)</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> */</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">protected</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">void</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> doGet(HttpServletRequest request,</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> HttpServletResponse response) </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">throws</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> ServletException, IOException {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">out</span></i><span style="color: black; font-family: "courier new"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "courier new"; font-size: 10pt;">"start timer creation : "</span><span style="color: black; font-family: "courier new"; font-size: 10pt;"> + </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">new</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Date());</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">try</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timer1</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">.createTimer();</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timer2</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">.createTimer();</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> } </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">catch</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> (Exception e) {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">out</span></i><span style="color: black; font-family: "courier new"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "courier new"; font-size: 10pt;">"timer creation failed "</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">);</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">throw</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">new</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> RuntimeException(</span><span style="color: #2a00ff; font-family: "courier new"; font-size: 10pt;">"timer creation failed "</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">, e);</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> System.</span><i><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">out</span></i><span style="color: black; font-family: "courier new"; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: "courier new"; font-size: 10pt;">"Done timer creation : "</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">);</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;">/**</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> * </span><b><span style="color: #7f9fbf; font-family: "courier new"; font-size: 10pt;">@see</span></b><span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> HttpServlet#doPost(HttpServletRequest request, HttpServletResponse</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> * response)</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"> */</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">protected</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">void</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> doPost(HttpServletRequest request,</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> HttpServletResponse response) </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">throws</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;"> ServletException, IOException {</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> doGet(request, response);</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">}</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">Overall, the code is quite simple. Some things are worth noting here is that local interfaces are used for the session beans, a servlet which needs to be invoked externally is used to create timers, also ‘</span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt; line-height: 115%;">timerService</span><span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">.getTimers()’ is used to find out the number of active timers for a session bean and also help control the number of running timers in the system, so the system will not be over stretched.</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>weblogic-ejb-jar.xml: some important configurations</b></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgag_yJyhVy31ZFdHnmihA3ib-s5Nh8ScgW7uU6jAlWBR0KbBWU01F_0Cxijqym4roftSsAUITfkaqUlwbVWOeqautV_VInIKvt0pX2OKOoshIuXPhF_uVedC_sfJe8FVPwGA-auaP8u74/s1600/admin1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgag_yJyhVy31ZFdHnmihA3ib-s5Nh8ScgW7uU6jAlWBR0KbBWU01F_0Cxijqym4roftSsAUITfkaqUlwbVWOeqautV_VInIKvt0pX2OKOoshIuXPhF_uVedC_sfJe8FVPwGA-auaP8u74/s640/admin1.png" width="640" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6hWiuOXwv0FnIkvDo6E2zMoK-5xOdLwDySVl_p8JinXcqfm-8fnmPQfLP3qfSj2l4ywBlcLmBWnt9cq13StbbebATeQAhnO89NEk11AbwEIoJWIGJ9gn4GgN-uS33Ses24NRxcefc9XQ/s1600/admin2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6hWiuOXwv0FnIkvDo6E2zMoK-5xOdLwDySVl_p8JinXcqfm-8fnmPQfLP3qfSj2l4ywBlcLmBWnt9cq13StbbebATeQAhnO89NEk11AbwEIoJWIGJ9gn4GgN-uS33Ses24NRxcefc9XQ/s640/admin2.png" width="640" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-mqh79kUZvWn1oM9szG4ue6QLcqv-ziExaTPqZbBiX4ZEVOp-cEVi_i2iQg-fuYXxRVw1AyeQukvC3EshsP0VNhr6SAEZIFUXm8jZVQ_ioTqsqnfW1rUQqbnFJpiiH7hmIlv-9JrznvA/s1600/admin3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-mqh79kUZvWn1oM9szG4ue6QLcqv-ziExaTPqZbBiX4ZEVOp-cEVi_i2iQg-fuYXxRVw1AyeQukvC3EshsP0VNhr6SAEZIFUXm8jZVQ_ioTqsqnfW1rUQqbnFJpiiH7hmIlv-9JrznvA/s640/admin3.png" width="640" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: teal; font-family: "courier new"; font-size: 10pt;"><?</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">xml</span><span style="font-family: "courier new"; font-size: 10pt;"> <span style="color: #7f007f;">version</span><span style="color: black;">=</span><i><span style="color: #2a00ff;">"1.0"</span></i> <span style="color: #7f007f;">encoding</span><span style="color: black;">=</span><i><span style="color: #2a00ff;">"UTF-8"</span></i><span style="color: teal;">?></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:weblogic-ejb-jar</span><span style="font-family: "courier new"; font-size: 10pt;"> <span style="color: #7f007f;">xmlns:wls</span><span style="color: black;">=</span><i><span style="color: #2a00ff;">"http://xmlns.oracle.com/weblogic/weblogic-ejb-jar"</span></i> <span style="color: #7f007f;">xmlns:xsi</span><span style="color: black;">=</span><i><span style="color: #2a00ff;">"http://www.w3.org/2001/XMLSchema-instance"</span></i> <span style="color: #7f007f;">xsi:schemaLocation</span><span style="color: black;">=</span><i><span style="color: #2a00ff;">"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-ejb-jar http://xmlns.oracle.com/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd"</span></i><span style="color: teal;">></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: #3f5fbf; font-family: "courier new"; font-size: 10pt;"><!--<u>weblogic</u>-version:10.3.2--></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:weblogic-enterprise-bean</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:ejb-name</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="color: black; font-family: "courier new"; font-size: 10pt;">Timer1SessionBean</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:ejb-name</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:stateless-session-descriptor</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:timer-descriptor</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:persistent-store-logical-name</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="color: black; font-family: "courier new"; font-size: 10pt;">timerst</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:persistent-store-logical-name</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:timer-descriptor</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:stateless-session-descriptor</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:weblogic-enterprise-bean</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:weblogic-enterprise-bean</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:ejb-name</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="color: black; font-family: "courier new"; font-size: 10pt;">Timer2SessionBean</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:ejb-name</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:stateless-session-descriptor</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:timer-descriptor</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:persistent-store-logical-name</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="color: black; font-family: "courier new"; font-size: 10pt;">timerst</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:persistent-store-logical-name</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:timer-descriptor</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:stateless-session-descriptor</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:weblogic-enterprise-bean</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:weblogic-enterprise-bean</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:ejb-name</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="color: black; font-family: "courier new"; font-size: 10pt;">Timer3SessionBean</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:ejb-name</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:stateless-session-descriptor</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:timer-descriptor</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:persistent-store-logical-name</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="color: black; font-family: "courier new"; font-size: 10pt;">timerst</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:persistent-store-logical-name</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:timer-descriptor</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:stateless-session-descriptor</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:weblogic-enterprise-bean</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: black; font-family: "courier new"; font-size: 10pt;"> </span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"><</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:timer-implementation</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="color: black; font-family: "courier new"; font-size: 10pt;">Clustered</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt;">wls:timer-implementation</span><span style="color: teal; font-family: "courier new"; font-size: 10pt;">></span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: teal; font-family: "courier new"; font-size: 10pt; line-height: 115%;"></</span><span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt; line-height: 115%;">wls:weblogic-ejb-jar</span><span style="color: teal; font-family: "courier new"; font-size: 10pt; line-height: 115%;">></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The most important things are that making sure the timers are cluster aware, and also using proper logical name for the persistent store (<span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;">timerst</span>), which will be configured in the administrator console.</div>
<div class="MsoNormal">
<br />
<br /></div>
<div class="MsoNormal">
<b>Admin console configuration:</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Since EJB timers will be running in a clustered environment, weblogic uses two tables managing timers: ACTIVE and WEBLOGIC_TIMERS. These two tables can be named differently. These tables can be created automatically by the weblogic or can be created by you manually. Before you configure the cluster, you need to create JDBC data sources. </div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSAqwFet0xbFUAJXaNWAlJEtl-U2BB9SSjg90dTwTHBapVtrAf1EhaZGMUIfDIACrSIRn8FTMqZsTgumPQpmSzBILLD44hgyfMqmxR9MKPuXyryoBm5FskTU_3f9VgKsvfHFB8BOjU9Mk/s1600/admin4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSAqwFet0xbFUAJXaNWAlJEtl-U2BB9SSjg90dTwTHBapVtrAf1EhaZGMUIfDIACrSIRn8FTMqZsTgumPQpmSzBILLD44hgyfMqmxR9MKPuXyryoBm5FskTU_3f9VgKsvfHFB8BOjU9Mk/s640/admin4.png" width="640" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgE6Ici6WaWg1gDlSXEkW2kRghQFu69Wl5nidxqQ9tzbnFsNDeS4reHdz7zMh393FXzTcHU3PGIb-M1aGtPuWuPM6NToZLuY-i4wCsJ2WsCHOftW2-GBbTClumxm3ywAmwlGa6EJAAbYg4/s1600/admin5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgE6Ici6WaWg1gDlSXEkW2kRghQFu69Wl5nidxqQ9tzbnFsNDeS4reHdz7zMh393FXzTcHU3PGIb-M1aGtPuWuPM6NToZLuY-i4wCsJ2WsCHOftW2-GBbTClumxm3ywAmwlGa6EJAAbYg4/s640/admin5.png" width="640" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<b>Persistence of timers</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
There are two different styles of persistence. One is file based, the other is database based. We used the database for persistence. </div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsFWHeWXiX28hc8FAZFtSSibRiKu9cdmhhawg43t75ZiMDebJnQ8W93jW4IC3xY2Z_harteihy1DrEW7dXRdDwjSQUtiqEgxSNoX6nSfezRWGvB5ib9V5z6yssHMeZZajyolhhdiaJ43Y/s1600/admin6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsFWHeWXiX28hc8FAZFtSSibRiKu9cdmhhawg43t75ZiMDebJnQ8W93jW4IC3xY2Z_harteihy1DrEW7dXRdDwjSQUtiqEgxSNoX6nSfezRWGvB5ib9V5z6yssHMeZZajyolhhdiaJ43Y/s640/admin6.png" width="640" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
A table called ABC_WLSTORE will be created in schema ABCSYS automatically by the weblogic. It can also be created manually. </div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The logical name (timerst) mentioned in the above screen shot is (must be) exactly the same as the value of ‘<span style="color: #3f7f7f; font-family: "courier new"; font-size: 10pt; line-height: 115%;">persistent-store-logical-name</span>’ in the weblogic-ejb-jar.xml. In our application we had two nodes in a cluster. The important lesson we learned was that creating only one persistence store that targets one migratable, as shown above, is the right thing to do. Do NOT create two persistent stores with each targeting one migratable. Do NOT create different persistent stores with the same data source and the same prefix name.</div>
<div class="MsoNormal">
<br />
<br /></div>
<div class="MsoNormal">
<b>Deploy and Run</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
After deploying the application, you can invoke <a href="http://www.blogger.com/post-edit.g?blogID=728531761603831483&postID=122068410712423856">http://server:port/context/<span style="font-family: "courier new"; font-size: 10pt; line-height: 115%;">TestTimerCreateServlet</span></a><span style="color: black; font-family: "courier new"; font-size: 10pt; line-height: 115%;"> </span>to create timers, and then you can monitor the log files and/or the data in the WEBLOGIC_TIMERS table to find out how the execution went. </div>
<div class="MsoNormal">
<br />
<br /></div>
<div class="MsoNormal">
<span style="color: teal; font-family: "courier new"; font-size: 10pt; line-height: 115%;"></span></div>
<div class="MsoNormal">
<b>Lessons learned</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>PostConstruct </b>: </div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We tried using a “PostConstruct” function in a session bean to create timers and had hoped that timers would be created when a session bean is deployed, but it failed. The sample code was </div>
<div class="MsoNormal">
@PostConstruct</div>
<div class="MsoNormal">
public void init() {</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timerService</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">.createTimer(60000,60000, </span><b><span style="color: #7f0055; font-family: "courier new"; font-size: 10pt;">null</span></b><span style="color: black; font-family: "courier new"; font-size: 10pt;">);</span></div>
<div class="MsoNormal">
}</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Exceptions:</div>
<div class="MsoNormal">
Exception after create timer : java.lang.IllegalStateException: [EJB:010193]Illegal call to EJBContext method. The bean is in "ejbCreate" state. It cannot perform null action(s). Refer to the EJB specification for more details.<br />
java.lang.IllegalStateException: [EJB:010193]Illegal call to EJBContext method. The bean is in "ejbCreate" state. It cannot perform null action(s). Refer to the EJB specification for more details.<br />
at weblogic.ejb.container.internal.BaseEJBContext.checkAllowedMethod(BaseEJBContext.java:147)<br />
at weblogic.ejb.container.internal.BaseEJBContext.checkAllowedToUseTimerService(BaseEJBContext.java:439)<br />
at weblogic.ejb.container.internal.TimerServiceImpl.createTimer(TimerServiceImpl.java:82)<br />
at weblogic.ejb.container.internal.TimerServiceImpl.createTimer(TimerServiceImpl.java:43)<br />
at weblogic.ejb.container.deployer.TimerServiceProxyImpl.createTimer(TimerServiceProxyImpl.java:60)</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Reason given by weblogic:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
From the EJB 3.0 Specification, page 84, http://www.jcp.org/en/jsr/detail?id=220<br />
<br />
The following steps describe the life cycle of a stateless session bean instance:<br />
<br />
- A stateless session bean instance’s life starts when the container invokes the newInstance method on the session bean class to create a new session bean instance. Next, the container injections the bean’s SessionContext, if applicable, and performs any other dependency injection as specided by metadata annotations on the bean class or by the deployment descriptor. The container then calls the PostConstruct lifecycle callback interceptor methods for the bean, if any. The container can perform the instance creation at any time — there is no direct relationship to a client’s invocation of a business method or the create method.<br />
- The session bean instance is now ready to be delegated a business method call from any client or a call from the container to the timeout callback method.<br />
------<br />
<br />
Therefore after the postConstruct callback has been executed the container can perform the instance creation at any time, so still it is in creating meanwhile the method createTimer doesn't allow that state.<br />
<br />
Hence, the workaround that you mentioned at the beginning of calling the EJB initialization of Timer after the creation of the stateless bean is a better approach.<br />
<br />
Finally the state of the bean that is triggering the IllegalStateException has correct behavior regarding to the EJB specification.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>ServletContextListener</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We tried using a ServletContextListener to create ejb timers during the context initialization.<span style="color: teal; font-family: "courier new"; font-size: 10pt; line-height: 115%;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="color: #646464; font-family: "courier new"; font-size: 10pt;">@EJB</span><span style="color: black; font-family: "courier new"; font-size: 10pt;"> Timer1SessionBeanLocal </span><span style="color: #0000c0; font-family: "courier new"; font-size: 10pt;">timer1</span><span style="color: black; font-family: "courier new"; font-size: 10pt;">;</span><span style="font-family: "courier new"; font-size: 10pt;"></span></div>
<div class="MsoNormal">
public void contextInitialized(ServletContextEvent arg0) {</div>
<div class="MsoNormal">
<span style="color: #0000c0; font-family: "courier new"; font-size: 10pt; line-height: 115%;">timer1</span>.createTimer();</div>
<div class="MsoNormal">
}</div>
<div class="MsoNormal">
It failed also.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Exception:</div>
<div class="MsoNormal">
javax.ejb.EJBException: EJB Exception: : java.lang.NullPointerException at weblogic.ejb.container.timer.ClusteredEJBTimerManager.createTimer(ClusteredEJBTimerManager.java:76) at weblogic.ejb.container.timer.ClusteredEJBTimerManager.createTimer(ClusteredEJBTimerManager.java:95)<br />
at weblogic.ejb.container.internal.TimerServiceImpl.createTimer(TimerServiceImpl.java:125)<br />
at weblogic.ejb.container.internal.TimerServiceImpl.createTimer(TimerServiceImpl.java:49)</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Reasons:</div>
<div class="MsoNormal">
The weblogic team asked us to apply a patch for this problem. But we never did because of some other constraints. </div>
<div class="MsoNormal">
<br />
<br /></div>
<div class="MsoNormal">
<b>timerService.getTimers()</b><br />
<br />
Sometimes this function call throws a NullPointerException<br />
<br />
weblogic.ejb.container.deployer.TimerServiceProxyImpl@3a2229fc<br />
java.lang.NullPointerException<br />
at weblogic.scheduler.ejb.internal.EJBTimerManagerImpl$TimerWrapper.getListener(EJBTimerManagerImpl.java:187)<br />
at weblogic.ejb.container.timer.ClusteredEJBTimerManager.getTimers(ClusteredEJBTimerManager.java:123)<br />
at weblogic.ejb.container.timer.ClusteredEJBTimerManager.getTimers(ClusteredEJBTimerManager.java:107)<br />
at weblogic.ejb.container.internal.TimerServiceImpl.getTimers(TimerServiceImpl.java:158)<br />
at weblogic.ejb.container.deployer.TimerServiceProxyImpl.getTimers(TimerServiceProxyImpl.java:74)<br />
<br />
Reason:<br />
The weblogic support team did not give a good explanation. It could be a bug in the weblogic.<br />
<br /></div>
<div class="MsoNormal">
<b>Server stop/restart</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
As long as there is one server in the cluster still running, the timers will still function, the application may run slower though. When all servers in the cluster stop, the timers will stop running. When at least one of the servers in the cluster restarts again, the timers will start running.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Application stop/restart</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
After the EJB 3 timer application stops, the timers will stop running. When the application restarts, the timers will NOT start running. The weblogic support team said it may be a bug.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Application undeployment/redeployment</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
When an EJB 3 timer application is undeployed, the timers will be removed from the system, the records related to the timers for this application in the WEBLOGIC_TIMERS table will be deleted. Sometimes, some records related to this application will still exist in the ACTIVE table (it may be a bug), but it won’t affect the future deployment of the application. When the application is redeployed, a new cycle starts again. We did not use “update” for the application redeployment often, we felt it should be avoided from our experience.</div>
<div class="MsoNormal">
Overall, we think stopping and then restarting an EJB 3 timer application should be avoided. Use the server stop/restart or application undeployment/redeployment.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>EJB 3.1 Timer</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
There are nice articles online regarding this new technology. Overall, the syntax is richer, the timer can be created declaratively. Since we do not have much experience on this, we do not have any to share on this.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Conclusions</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Overall, EJB 3 timer provides a nice way to schedule tasks in jee environment. How to create ejb timers and use them effectively in a clustered environment is not very straightforward. We went through a sample application, explained the implementation and configuration in weblogic 10.3.2, and also shared the lessons we learned. We hope this will provide some useful information to users when they use EJB 3 timers in their applications.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Acknowledgements</b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Big thanks to my colleague Lee Slezak at HP for constructive suggestions.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<a href="https://docs.google.com/leaf?id=0B8bUUPgDhWkGM2E5NDkyMjUtZGVjNi00ZjMyLWIxMjUtOTAxOGQwMjgwMmRi&hl=en">source code</a> </div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<a href="https://docs.google.com/leaf?id=0B8bUUPgDhWkGMDZiMmVjM2ItNjVmMy00OGI5LWIzZDctZTJmYzI0ZWVhOGY2&hl=en">deployable ear</a><br />
<br />
<br />
Other blogs from me:<br />
<a href="http://shaoxiongyang.blogspot.com/2016/06/compile-xsl-files-and-store-in-cache-to.html" target="_blank">Compile xsl files and store in cache to improve XSLT performance</a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
Shaoxiong Yanghttp://www.blogger.com/profile/07891797389929303648noreply@blogger.com23