Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running plain java classes in a server

 
Giridhar Agoram
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
1) Can we run plain java classes in a server instead of a JVM
2) If yes, what are the pros / cons
 
Harish Kashyap
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you be a bit more elaborate when you say "run plain java classes in a server instead of a JVM"

can you be specific on "server" here. Because a server is just an application that responds to incoming requests and thus serving the clients. That server application can be a java class.

To run a java class, you need 'java' interpretter that needs jvm to execute.

even your server might be running under a jvm.
 
Giridhar Agoram
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me elaborate..

For a certain requirement, a plain java class running in a JVM wud suffice but my architect is insistent on deploying it in a server. So, I need the pros & cons of running this class in a server so as to argue for / against this design.

Thanks
Giridhar
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean running as a "service" - ie always running in the background and not tied to a particular user?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like this definition of server: A process that accepts connections from clients. This kind of environment is necessary if you want the code to run on another machine or a separate process on your own machine. You connect, send your request, it does the work, sends a response.

Your architect may just want to run one copy of the code on some machine so that you or any other user can connect and have it do some work. Talk it over see what reasons they have ... better sharing, central deployment, central management for start & stop, etc. And see how they define "server". It might be ok for your POJO to open a socket and act as a server itself, or they might have reason to run within a container like a servlet or EJB engine.
 
anupa oru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I also same kind of requirement. I have plain simple java class where class has its own main method, which I wanted to run in JBoss 3.2.6 so any user can use that class. To be specific I have JMS class which just send and receive messages to server. I created destination within JBoss so my JMS class has to send message to registered destination in JBoss. Could anybody enlighten me on this I know that JBoss support deployment of POJOs.
Thanks
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, you've added the special sauce that the previous part of the thread didn't have ... the JMS listener! You should be in great shape. Your listener can call methods on a POJO like String, so it can call methods on your class just as well. It can even invoke main() since main is a perfectly normal public static method.

MyClass.main( args );

I personally know zip about deployment, but you should be able to put your POJO in a "utility jar" (is that a common EJB term or just WebSphere?) or the same package & jar as your listener.

I'm a little curious what this thing is going to do. If you run main() you won't get any return value. If it just does a little work and doesn't need to report back, it should be fine, tho.

Sorry if that start out a bit smart-a** in tone. It's neat to realize how little magic there is in the world. Running inside a server is not that big a deal in many ways, and main() has no voodoo at all - it just happens to be the method that java.exe likes to call.

Let me know if all that works out for you!
[ June 10, 2005: Message edited by: Stan James ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic