Mohit G Gupta

Ranch Hand
+ Follow
since May 18, 2010
Mohit G likes ...
Eclipse IDE Chrome Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
4
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mohit G Gupta

"every other hour" means "every second".



Then shouldn't the Schedule annotation be as:



Question: Why are we using hour="12/2" ?

Source:EJB 3.1 Specification



18.2.1.3.9 "Every other hour within the day starting at noon on the 2nd Tuesday of every month."

@Schedule(hour="12/2", dayOfMonth="2nd Tue")

Question 1:Why is it mentioned that timer will run every other hour ?
As per my understanding,The above created timer will run every 2 hr within the day starting at noon on the 2nd Tuesday of every month

Source 12.1.3. Running the Example Program – Declarative Scheduling

OCP JavaEE 6 EJB Developer Study Notes by Ivan A Krizsan Version: April 8, 2012



I had modified the example on Eclipse as below:


@Schedule(second = "20, 45", minute = "*", hour = "6-23",
dayOfWeek = "Mon-Sun", dayOfMonth = "*", month = "*", year = "*",
info = "MyTimer")
private void scheduledMethod1(final Timer inTimer)



Below is the output :



As written in the explanation for the example,

scheduling collisions are resolved by GlassFish by creating a new instance of the stateless session bean and invoking the timeout callback method to be executed next on the new instance



Question 1-A:When it is decided to create a new instance ?
As seen in the output provided,the new instance is created when a new timeout callback method is to created. eg:

scheduledMethod1 is executed with a different instance after scheduledMethod2 is executed

Question 1-B:So,when will the next instance be created ?

I see that both the methods keep on executing with instance 2 and 3 in a random order.
Question 2:So,will these methods stop executing after the criteria in the cancelOverdue is met or there is any other way too ?

I have configured the hour to be hour = "6-23".
Question 3 :So, shouldn't the timer till run 23 hr ? ( I see it running past 23 too,Please see in the output provided)
Thanks James for the reply.

A2 When executing StatelessSession2Bean, the principal is changed from johnny to runas-superuser. At this point, the role of the user is changed from plainusers to runasadmin



So,when the following line of code executes in StatelessSession1Bean, the caller is in the role "plainusers" :



However,when the superusersOnly executes in the StatelessSession2Bean,then the caller role changes from "plainusers" to "runasadmin"

Please let me know if I have understood correctly
Thanks James for the reply.
However I still have queries

As stated in Statement A,Timeoutannotation or timeout method in the deployment descriptor are used to specify single timeout callback method.
and Statement B says that If the bean implements the TimedObjectinterface, the Timeoutannotation or timeout-method deployment descriptor element can only be used to specify the ejbTimeoutmethod

ejbTimeoutmethod is also timeout callback method

The 2 statement looks similar But I see there is on text(see text in bold) that creates a difference.
Question:Can someone throw more light on the text ?

Source: EJB 3.1 Specification

18.2.5.1 Timeout Callbacks for Programmatic Timers



A.All timers created via one of the TimerService timer creation methods for a particular component use a
single timeout callback method. This method may be a
i)method annotated with the Timeoutannotation
(or a method specified as a timeout method in the deployment descriptor) or
ii) the bean may implement the javax.ejb.TimedObjectinterface.

B.If the bean implements the TimedObjectinterface, the Timeoutannotation or timeout-method
deployment descriptor element can only be used to specify the ejbTimeoutmethod



As stated in statment B,the Timeoutannotation or timeout-method deployment descriptor element can only be used to specify the ejbTimeoutmethod.
Question: Can someone provide a example explaining the same ?

Source:11.3.8. Changing the Invocation Security Role
OCP JavaEE 6 EJB Developer Study Notes by Ivan A Krizsan Version: April 8, 2012


The explanation for the example is given as:

When executing in the StatelessSession1Bean, the name of the principal is "johnny" and the
caller is in the security role "plainusers".

A. The first session bean, StatelessSession1Bean, did not succeed in invoking the
superusersOnlymethod on the second session bean, StatelessSession2Bean.
This is not entirely surprising, as the caller is in the role "plainusers" when executing in the
first session bean
.

B. When executing in the StatelessSession2Bean, the name of the principal has changed to
"runas-superuser" and the caller is neither in the security role "superusers" nor in the role
"plainusers".

C. Remember that we configured a user named "runas-superuser" in the GlassFish server
which belongs to the “super-users” group.
So despite the "runas-superuser" belonging to the same group as the user "ivan", running
with the former principal still does not allow us to invoke the superusersOnlymethod on the
StatelessSession2Bean. This is because the "runas-superuser" is mapped to another security
role, the "runasadmin" role
.

My Understanding:
When mSessionBean1.greeting(theRequestNameParam); is executed from EJBClientServlet,name of the principal is "johnny" and the caller is in the security role "plainusers".
However,when StatelessSession1Bean tries to invoke mSessionBean2.superusersOnly()

Question1: The caller is in the role "plainusers" or "runasadmin" ?
Question2.Statement A states that caller is in role of "plainusers" while the statement C states caller is in "runasadmin" role(See statements in Italics).Aren't the two contradictory ?
Even after many tries,its still not working for me.