How do you get Jetty not to work on request?



  • I'm studying Java, Jetty, Servlet. I want to study Spring later. Is that what the question is, how do you get the server to do my code permanently or with some frequency without a client's request?
    For example, I have sensors that need to gather information in advance, and later, at the client ' s request, just get it out quickly. There are also executive devices that need to be forced to work without the participation of a person (open the tap, insert the ventilation).
    Server's very notion is that he's dumb to wait for him to get kicked and can't do it any other way. I understand that you can get the planner to do every five seconds a request for a server, but it's a crutch, I'd like to hear the right academic solution, as they do (e.g. in enterprises)?
    I don't want to move the Jetty core of the system to some other place or to double the logic by doing the outside violin.

    I still don't know what application server is, maybe I need it. I mean, maybe appserver is different from the usual web server and the silver container that he can do the code himself for some internal dial and trigger?

    A quick look at Spring's book has noticed that there are some tasks and a planner, maybe that's what I need?

    I'm planning on using SBD and client for Androids, and maybe there's no point in keeping the logic of my program in the ears, but moving it to the extra program or to the CSB, and Jetty leaving it for the WEB-page? How is it right to do the perfect architecture?

    I'll notice that it's all on ancient Raspberry Pi and I'm thinking about using it as a controller or as a server. Electricity can be saved as well as easily out of the situation by replacing the malfunctioning device and re-establishing the system from a backup copy. Besides, it's a messy system.

    The replacement of Java technology is requested not to offer, the choice is made (long learning the popularity of programming languages, etc.). The plans are great, but I'm a newcomer, and I'm very smart not to be explained unless there's another way.



  • We need to look at the ServletContextListener and asynchronic. ServletContextListener redefinition contextInitialized and launch the necessary asynchronous disk:

    public class BackgroundJobManager implements ServletContextListener {
    
    private ScheduledExecutorService scheduler;
    
    @Override
    public void contextInitialized(ServletContextEvent event) {
        scheduler = Executors.newSingleThreadScheduledExecutor();
        scheduler.scheduleAtFixedRate(new SomeDailyJob(), 0, 1, TimeUnit.DAYS);
        // или что-то вроде этого...
    }
    
    @Override
    public void contextDestroyed(ServletContextEvent event) {
        // убить таск при останове сервера:
        scheduler.shutdownNow();
    }
    

    }

    Of course, contextListener needs to be registered on the web.xml.
    A more complete example can be found here: https://examples.javacodegeeks.com/enterprise-java/jetty/jetty-web-xml-configuration-example/




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2