Results 1 to 3 of 3
  1. #1
    Gudradain is offline Member
    Join Date
    Nov 2008
    Posts
    44
    Rep Power
    0

    Default Need Help with Java EE

    I have a good knowledge of Java SE but I'm a complete beginner to Java EE. I just need some directions on how to solve my problem. Here is a simplified version of the problem

    I have a class that do the following :

    Java Code:
    public class RandomNumber implements Runnable{
    	
    	long randomSum = 0;
    	
    	public RandomNumber(){
    		new Thread(this).start();
    	}
    	
    	public synchronized long get(){
    		return randomSum;
    	}
    	
    	public synchronized void plus(long number){
    		randomSum += number;
    	}
    
    	@Override
    	public void run() {
    		while(true){
    			long n = (long) (Math.random()*10);
    			plus(n);
    			System.out.println(get());
    			try {
    				Thread.sleep(1000);
    			} catch (InterruptedException e) {
    				e.printStackTrace();
    			}
    		}
    	}
    }
    I want this code to run forever on a server that I don't have physical access to but that seems to be made to run Java EE apps.

    Then I want to display on a web page the current value of the randomSum value (at the moment the page is load. Real time update would be a bonus).

    So basically my problem in 3 lines is :

    1. RandomNumber
    2. ?????
    3. Awesome web page

    I'm completely lost and currently going through this whole tutorial but can't seems to put all the piece together to make it works.

  2. #2
    Gudradain is offline Member
    Join Date
    Nov 2008
    Posts
    44
    Rep Power
    0

    Default Re: Need Help with Java EE

    I think I found a hint on one part. If I want to repeatedly call a method on fix interval I will need to put that stuff into an EJB and use the timer service. Right?

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,848
    Rep Power
    5

    Default Re: Need Help with Java EE

    correct, that is one way to do it and in your case probably the easiest. Generally servers have a built in scheduler that you can use, but then you'd need access to the server itself to configure a job.

    As for the web part - the JavaEE way to do it is to use Javaserver Faces, but you're not limited to that at all, you can use any popular web framework such as Spring or Wicket. Or if you need a really simple page only, you could use good old servlets & JSPs to do the job. Then at least you have something to put into google which is a little more specific than "JavaEE", which is a huge flipping collection of APIs and frameworks in stead of one thing only.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •