Win a copy of Head First Android this week in the Android forum!

Mohammad Ali Asgar

Ranch Hand
+ Follow
since Sep 05, 2013
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
5
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mohammad Ali Asgar

I need to implement a scheduler for running a periodic job. There is a table in a Cassandra database in which one column contains the creation time-stamps of rows and another column contains the status which is "open" by default. I need to create a job which should run periodically in every 10 minutes and query Cassandra to find out whether any rows with the "open" status are 5 or more days older. If so, the job should then change the status of all such rows from "open" to "closed". That's it.

The above seemingly simple problem is part of a large industry-strength OSGi application and I have been asked to pick the best 3pp option among:

1. Apache Quartz
2. Apache Sling
3. Apache Zookeeper


My challenges are:

1. There will be multiple instances of the application (and, therefore, multiple instances of that periodic job) running on multiple JVM's in the live environment interacting with the same Cassandra database with thousands of rows. [Do I need to handle concurrency from my Java code?]
2. I know Quartz does not guarantee persistence but do I really need it in my case?
3. Which of the 3pp solutions (Quartz, Sling, Zookeeper) can I use?
Hello,

I need to implement a scheduler for running a periodic job. There is a table in a Cassandra database in which one column contains the creation time-stamps of rows and another column contains the status which is "open" by default. I need to create a job which should run periodically in every 10 minutes and query Cassandra to find out whether any rows with the "open" status are 5 or more days older. If so, the job should then change the status of all such rows from "open" to "closed". That's it.

The above seemingly simple problem is part of a large industry-strength OSGi application and I have been asked to pick the best 3pp option among:

1. Apache Quartz
2. Apache Sling
3. Apache Zookeeper


My challenges are:

1. There will be multiple instances of the application (and, therefore, multiple instances of that periodic job) running on multiple JVM's in the live environment interacting with the same Cassandra database with thousands of rows. [Do I need to handle concurrency from my Java code?]
2. I know Quartz does not guarantee persistence but do I really need it in my case?
3. Which of the 3pp solutions (Quartz, Sling, Zookeeper) can I use?
5 years ago
Thank you, Michael, so so much for going through the trouble of writing a long, long post.

So vibrant that I read it in one go!

Would you kindly touch on "managed beans" that I mentioned in my confusion-1?

Also, in confusion-6, does GlassFish MQ (the built-in messaging service provider in Glassfish) belong to the EIS tier?

___ softwarelover
Dear all the Java EE experts, who are having fun with Java EE, please allow me to have some fun too! Please, please, help me on each confusion I mention below. I cannot sleep at night.

I have a strong background and certification in Java SE 7. I am investing heavily on Java Enterprise Edition 7 by trying out things using Netbeans 8 and GlassFish 4. There are things blocking my way about which the more I read references I more confused I become. Kindly help me clear the way.

Confusion-1: I have started with EJB. There are so many types of beans out there! Other than EJB (stateful, stateless, singleton, message-driven), I am coming across more types. Would you please tell me what is a managed bean?

Confusion-2: I see that EJB's are sometimes referred to as CDI beans. What are these CDI creatures actually?

Confusion-3: Are all types of beans (EJB, managed, entity, CDI, others I have not seen yet) supposed to conform to the Java Beans Model by defining SET and GET methods? Is that a mandatory requirement?

Confusion-4: From my Java EE client application, I can easily obtain a reference to a stateless session bean with the @EJB annotation. But I am having a hard time trying to distinguish between @EJB, @Inject, and @Resource.

Confusion-5: Regarding message driven beans, what is the difference between a MessageDrivenContext and transaction context? When would I prefer one to the other?

Confusion-6: Where does a messaging service provider fit in the n-tier hierarchy? The EIS tier? Aren't queues/topics part of the messaging service provider? Then why is a queue configured separately for use with Glassfish MQ?

Confusion-7: This is giving me a really hard time. JDNI. I know that java:comp/env is a naming space/environment that is private to each EE component, but what is its role actually? Is it used when a component attempts to find a reference by using portable global JDNI lookup? Is it used when a component attempts to find a reference by using @EJB?
Thanks, Tim, for the reply!

Do I have to run commands in step2 and step3 everytime I need to run the client?
I have two laptops. Both are connected to the Internet via my home wi-fi router.

laptop1: testing Java Enterprise Edition 7 applications, using NetBeans 8 and GlassFish 4
laptop2: testing Java Standard Edition 7 applications, using Eclipse Mars

Here is what I did on laptop1:

- Packaged a simple EJB component and a library containing the EJB's remote interface into an EAR.
- Deployed it successfully on GlassFish.
- Packaged an enterprise application client and the same library containing the EJB's remote interface into a module and deployed it separately on GlassFish.
- Both applications (EAR and client module) were running fine and the client was able to invoke the ejb component's method using dependency injection (@EJB).

Here is what I am facing problems with while doing something involving both laptop1 and laptop2:
I am trying to create a stand-alone non-EE client on laptop2 in order to invoke methods on the remote EJB component residing on laptop1. I am following this document https://glassfish.java.net/docs/4.0/application-development-guide.pdf

The steps written in that document are below. Please see my questions embedded below.

STEP1
InitialContext ctx = new InitialContext();
BeanRemote bean = (BeanRemote) ctx.lookup("com.acme.BeanRemote");
It does not look like JNDI to me. Where is java:global in it? Is this really portable or GlassFish specific?

STEP2
Copy the as-install/lib/gf-client.jar file to the client machine and include it in the classpath on the client side. How do I do it and where do I find the classpath on the client side?

If there is no GlassFish Server installation on the client machine (duh!), you must also copy the as-install/modules directory to the client machine and maintain its directory structure relative to the as-install/lib/gf-client.jar file. Relative in the classpath?


STEP3
Set the following system properties for the JVM startup options:
-Dorg.omg.CORBA.ORBInitialHost=${ORBhost}
-Dorg.omg.CORBA.ORBInitialPort=${ORBport}

Here ORBhost is the GlassFish Server hostname and ORBport is the ORB port number (default is 3700 for the default server instance, named server).
How do I set the above startup options for the JVM on the client side?

STEP4
Make sure the etc/hosts file on the client machine maps the GlassFish Server hostname and external IP address. In this file on each laptop do I need to tag a fully qualified domain to the computer name and place it next to the IP assigned by the wi-fi network?
Thanks, Jeanne, for the reply. I am in the Toronto area in Canada.

I have randomly picked some of the NYC jobs found on the link you provided. Here is one sample taken from them. This asks for these:
Service oriented architecture - Rest/SOAP Services, SPRING, HIBERNATE.

Aren't these technologies used with EE, as opposed to SE? Some employers use the term "core Java" very wrongly.
Thank you everyone for all your replies. Yes, I have experience. And, Java is my passion. As one of you compared Java with an ocean, I tool believe so. I am now focusing more on EE now that my core is officially solid with SE. It is just that I was expecting to see jobs asking for experience in Standard Edition Java = core Java but instead I found tons of jobs asking for experience in Enterprise Edition Java.

One of you did mention that some core Java jobs are available. I have yet to find some. I put my eyes on the Indeed website to look for such jobs.

Another thing is that, I had fun with threads in SE. But EE, in spite of providing a concurrent API, feels less flexible and more inhibiting on threading since a lot of threading jobs are transparently handled by containers in application servers.
This writing is not for those who are pursuing OCA/OCP certification on Java SE 7/8. Please leave this page.

But, to those who already possess OCA/OCP certificates (like, myself) on Java SE 7/8, I would like to say that I regret having obtained OCP on Java SE 7 because I had invested so much time+money on it, buying and trying Mala Gupta's book, Enthuware mock tests, etc etc, with a false impression that after being certified the prospective employers will look at me differently.

Alas, in the job market, there hardly is any job asking for SE credentials. All of them ask for EE knowledge/experience on things like application servers, JMS, JPA, RESTful web services, JSF, Servlets, Spring, Struts, etc.

My question to experts: Is it really worth pursuing any certification on any Java technology that has "SE" in it?
Hi All,

I have a licensed version of the question bank for OCA SE 7 exam (1Z0-803). I am in the middle of practicing the tests one by one but I am not able to see any 7th test. I have got 6 tests followed by the Last Day Test. When I click on the average scores option that is populated with real data from the server, it shows a 7th test in addition to the last day test.

Please let me know how I can get that extra test. Please note that each test contains 70 questions, not 90. So, my version is up-to-date with the current exam format.

Thank you.

Best Regards,
softwarelover


Interesting outputs:

true
true
false

Because of that new operator, two copies of "OCA SE7" exist.

Thanks Pawet,

Yes, I have realized that. In fact, as I have come to know, if "name" is null, then

this(name != null ? new File(name) : null); evaluates to this((File)null); not this(null);

As per JLS: http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.25-300-C

if one of the second and third operands is of the null type and the type of the other is a reference type, then the type of the conditional expression is that reference type.

That is why null is type-cast into (File)null. So, there is no ambiguity and FileInputStream(File) is chosen by the compiler.

And, lastly, this((File)null) is analogous to
File file = null;
new FileInputStream(file);
Hello,

As I was reading Mala Gupta's book, I came to a page where there is an interesting discussion on a scenario where there are two valid, overloaded methods but where the compiler will get confused and then report a compile-time error in response to certain inputs.

Here are the methods.



I quote from the book: "... but an issue arises when you try to execute this method using values that can be passed to both versions of the overloaded methods. In this case, the code will fail to compile ..."

Here is the code showing the use of the methods:



Because an int literal value can be passed to a variable of type double, both methods are acceptable candidates for literal values 2 and 3, and therefore the compiler fails to decide which method to pick.

This is where I get confused when I take the above concept with me and dive further into the book to the final chapter, the chapter of exceptions. There, the writer introduces from Java 7 API two overloaded constructors of FileInputStream.

1. public FileInputStream(String name) throws FileNotFoundException {.....}
2. public FileInputStream(File file) throws FileNotFoundException {.....}


The writer also says that, according to the Java 7 API source code, here is the definition of the version that takes a String object as the argument:



Now, if "name" is indeed null, this(name != null ? new File(name) : null); evaluates to this(null); which in turn is equivalent to invocation of FileInputStream(null); but then both FileInputStream(String) and FileInputStream(File) become possible choices to be invoked with a null value. Does it not give rise to ambiguity? So, isn't there a compile-time error for that?

I do understand that eventually a FileNotFoundException is raised, but it is a separate issue which comes later. How is the ambiguity resolved before that?

Hi,

Thanks. That's good to know. OCAJP I SE7 and OCPJP II SE7 are in my certification plan.

__ softwarelover