...
 new Thread(new Runnable() {
    public void run() {
       // retrieve DB data
       try{ Thread.sleep(10000);
       }catch(InterruptedException e){}
    }).start();

解决方案 »

  1.   

    可以在数据库的表里面建立新字段 :creatTime updateDate    定时的检索这些字段的值 来取得最新版本!~
      

  2.   

    使用Timer和TimerTask
    我觉得楼上说的效率确实是应该考虑的问题
      

  3.   

    对呀 用jms 我有贴过代码的
      

  4.   

    teafang(学习) :
    把你的帖子的链接贴上来或者再贴一遍代码了,谢谢!
      

  5.   

    公共类
    package commonclass.msgs;import java.util.*;
    import javax.jms.*;
    import javax.naming.*;import commonclass.*;public class TopicBase {
      public final static String JNDI_FACTORY =
          "weblogic.jndi.WLInitialContextFactory";
      public String FactoryName = "";
      public String TopicName = "";
      public InitialContext ctx = null;
      public TopicConnectionFactory TCF = null;
      public Topic topic = null;
      public TopicConnection TC = null;
      public TopicSession TSession = null;  public TopicBase() {
        getTopicInit();
      }  private void getTopicInit() {
        PropertyFile pFile = new PropertyFile();
        pFile.setPropFile("c:/webinfo/web.properties");
        FactoryName = pFile.getProp("CFName");
        TopicName = pFile.getProp("TopicName");
        try {
          ctx = getInitialContext();
          TCF = (TopicConnectionFactory) ctx.lookup(FactoryName);
          topic = (Topic) ctx.lookup(TopicName);
          ctx.close();
          TC = TCF.createTopicConnection();
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }  private static InitialContext getInitialContext() throws NamingException {
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
        return new InitialContext(env);
      }  public void Start() {
        try {
          TC.start();
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }  public void Stop() {
        try {
          TC.stop();
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }  public void Close() {
        try {
          TSession.close();
          TC.close();
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
    }///////////////////////////
    发送程序  在你的改动数据库的程序里创建他的实例
     调用public void publish(String msgStr) msgStr就是消息的内容
    //////////////////////////
    package commonclass.msgs;import javax.jms.*;public class Publisher
        extends TopicBase {
      private TopicPublisher TPublisher = null;
      private TextMessage TMSG = null;
      private String MsgContent = "no message set";
      public Publisher() {
        super();
        try {
          TSession = TC.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
          TPublisher = TSession.createPublisher(topic);
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }  private void setMessage(String msg) {
        MsgContent = msg;
      }  public void publish(String msgStr) {
        setMessage(msgStr);
        try {
          TMSG = TSession.createTextMessage(MsgContent);
          TPublisher.publish(TMSG);
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }  public void closePublisher() {
        try {
          TPublisher.close();
          Close();
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    //////////////////
    接收  在onMessage(Message message)里改写你的代码 或者继承他重载这个方法
    但是你要保证这个对象的生命周期。保证他在整个web页面被浏览的时候都存在如放在applet里等
    其他方法我还没找到 有更好的方法请告诉我 [email protected]
    //////////////////
    package commonclass.msgs;import javax.jms.*;public class Subscriber
        extends TopicBase
        implements MessageListener {
      protected boolean ifDurable = false;
      protected TopicSubscriber TSubscriber = null;
      protected static String clientID;  public Subscriber() {
        super();
        try {
          TSession = TC.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
          TSubscriber = TSession.createSubscriber(topic);
          TSubscriber.setMessageListener(this);
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }  public Subscriber(String clientid) {
        super();
        ifDurable = true;
        clientID = clientid;
        try {
          TC.setClientID(clientID);
          TSession = TC.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
          TSubscriber = TSession.createDurableSubscriber(topic, clientID);
          TSubscriber.setMessageListener(this);
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }  public void onMessage(Message message) {
        String msgText = "";
        String msgID = "";
        try {
          msgID = message.getJMSMessageID();
          if (message instanceof TextMessage) {
            msgText = ( (TextMessage) message).getText();
          }
          else {
            msgText = message.toString();
          }
        }
        catch (JMSException jmse) {
          jmse.printStackTrace();
        }
        System.out.println("There is a Message received:");
        System.out.println(msgText);
      }  public void closeSubscriber() {
        try {
          TSubscriber.close();
          Close();
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
    }嘿嘿刚写出来还没测试 不过估计没什么大问题
    最近刚研究jms欢迎大家和我交流[email protected]
      

  6.   

    这个是pub/sub模式的 你用bs的 会有多个页面同时接受消息 所以用发布/订阅 带参数的构造函数用于创建持久的消息订阅者。没参数的构造函数创建的对象不能接受到他被创建之前的消息 关于消息订阅者请参阅jms的文档
    http://java.sun.com/products/jms/tutorial/1_3_1-fcs/doc/copyright.html
      

  7.   

    真是惭愧,小弟对JMS还没什么概念,看看IBM教程先。谢谢 teafang(学习)