java - Java中如何知道DB上是否有 Action ?

标签 java

我有两个应用程序A和B,我需要修改B中来自A的数据库的数据(检查特定表中是否有新记录)。 我在 B 上放置了无限循环,但我认为这不是最好的解决方案。

int i = 0;

    for(;;)
    {
        for(i = 0; i <= 600000;)
        {
            i++;    
        }
        //Check if there is a new record in a table from app A.

        String raw_xml = B.checkDB();
        //if there is a new record in a table from app do the
        // function doPingTest ()
        if (raw_xml!= null)
        {
            new TestB().doPingTest(raw_xml);
        }

        i = 0;
    }

最佳答案

在对其他替代方案进行一些测试后,这是最好的解决方案:

for(;;)
{
  while(true)
  {
    //sleep one minute
    Thread.sleep(60 * 1000);
    //Check if there is a new record in the DB
    String raw_xml = B.checkDB();
        if (raw_xml!= null)
        {
            new TestB().doPingTest(raw_xml);
        }
  }         
}

关于java - Java中如何知道DB上是否有 Action ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57121672/

相关文章:

java - 是否可以使用泛型但需要特定的父类型?

java - 找不到速度模板资源

java - 如何检测丢失的 LOG4J2 配置?

java - 测量 Kafka Streams 中的处理吞吐量

java - 通过 wifi 连接 Java 套接字?

java - 外部 Apache tomcat 服务器

java - 错误: "Unable to obtain ZonedDateTime from TemporalAccessor" for format "yyyy-MM-dd hh:mm:ss z"

java - setOnClickListener 方法中的重复代码 - android - java

java - 是否可以从泛型方法返回原始对象?

java - Android II JAVA 排序对象的 ArrayList