Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:54:43+00:00 2026-05-31T00:54:43+00:00

My Web application is polling a Database for changes and Showing those changes on

  • 0

My Web application is polling a Database for changes and Showing those changes on a JSP. The Database is changed by a legacy System and no possibility to get an event on Data change.

My approach is to poll the Database and synchronizing the data with an Application bean. If the data has changed, I use a push mechanism to update the JSP page. The Thread that polls the database is spawned by the Application bean.

I’m already using spring in my Web application so I want to use the spring @Scheduled annotation because I don’t want to spawn a Thread and let Spring handle the periodical execution. But the the Method is not execute Periodically.

I’m using Tomcat and MS Sql Server.

My Application bean looks like this

@Named("agentData")
@Scope("application")
public class AgentDataBean implements Serializable {
...
@Scheduled(fixedRate=5000)
public void loadData() { 
// do database poll
}
...
}

My Spring and Web Xml look like this

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">

<display-name>JavaServerFaces</display-name>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-application-config.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
</context-param>

<context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>#{login.theme}</param-value>
</context-param>

<!-- Welcome page -->
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

<!-- JSF mapping -->
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- Map these files with JSF -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<?xml version="1.0" encoding="UTF-8"?>
<beans 
xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" 
xmlns:task="http://www.springframework.org/schema/task"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/task
   http://www.springframework.org/schema/task/spring-task-3.0.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
   http://www.springframework.org/schema/aop
   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/config/database.properties" />
</bean>

<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
    id="dataSource" p:driverClassName="${jdbc.driverClassName}"
    p:password="${jdbc.password}" p:url="${jdbc.url}" p:username="${jdbc.username}" />

<!-- Activates annotaion-based bean configuration -->
<context:annotation-config />

<!-- needed is for @Configurable -->
<context:component-scan base-package="de.cpls.alo.dashboard" />
<tx:annotation-driven />
<!-- Activates @Scheduled and @Async annotations fpr scheduling -->
<task:annotation-driven executor="executorWithPoolSizeRange" scheduler="taskScheduler"/>

<task:executor id="executorWithPoolSizeRange"
              pool-size="5-25"
              queue-capacity="100"/>

<!-- Defines a ThreadPoolTaskScheduler instance with configurable pool size. 
The id becomes the default thread name prefix. -->             
<task:scheduler id="taskScheduler" pool-size="1"/>  

This question is a solution approach to this Question
Is there a best practice for showing database changes on a JSP

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:54:48+00:00Added an answer on May 31, 2026 at 12:54 am

    My Solution, using a SchedulerComponent

    @Named("scheduler")
    @Component
    public class SchedulerComponent {
    
    private List<IScheduledComponent> components;
    
    public SchedulerComponent() {
        this.components = new ArrayList<IScheduledComponent>();
    }
    
    
    public void register(IScheduledComponent component){
        this.components.add(component);
    }
    
    
    @Scheduled(fixedRate = 5000)
    public void doAllWork() {
        try {
            for(IScheduledComponent component : this.components){
                component.doWork();
            }
    
            System.out.println("SchedulerComponent.doAllWork()");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    }
    

    An Interface for Scheduled Execution

    public interface IScheduledComponent {
        public void doWork();
    }
    

    An let the Data Bean Implement the Interface and Register to the SchedulerComponent

    @Named("agentData")
    @Scope("application")
    public class AgentDataBean implements Serializable,IScheduledComponent {
    ...
    public void doWork() {
      // do database poll
    }
     ... 
    }
    

    Now i got Scheduled with Spring and i got FacesContext in AgentDataBean so i can Execute a Icefaces Push.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our web application sends e-mails. We have lots of users, and we get lots
We've a requirement to create a web application, where data isretrieved from the FTP
I have a web server hosting an HTTP chat application that works with long-polling.
I have a Python application. It has an SQLite database, full of data about
I'm working on a web application that needs to frequently poll the server database
I have a Java web application connecting to an Oracle database running on another
I have a web application that is polling a web service on another server.
In my web-application, i make extensive use of a database. I have an abstract
I'm currently working on a legacy ASP.NET 2.0 web application using a MySQL 5
I'm using NServiceBus in a pub/sub application for event notifications on a web application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.