Java 递增一个数字,然后在输入固定记录后返回?

Java 递增一个数字,然后在输入固定记录后返回?,java,eclipse,web-services,wsdl,auto-increment,Java,Eclipse,Web Services,Wsdl,Auto Increment,实际上,我想将变量设置为6位数字,当记录达到999999时,将其递增并重置。我只想在通过Java编写的客户机对web服务执行特定调用时增加值。你能建议一下做这件事的方法吗?任何其他方法,然后创建一个数据库并在其中输入值,然后在计数达到999999时刷新值。 谢谢我将用单例编写一个示例,但我建议使用spring或容器等价物来实现这一点 public class Counter { private static Counter instance; private static int

实际上,我想将变量设置为6位数字,当记录达到999999时,将其递增并重置。我只想在通过Java编写的客户机对web服务执行特定调用时增加值。你能建议一下做这件事的方法吗?任何其他方法,然后创建一个数据库并在其中输入值,然后在计数达到999999时刷新值。
谢谢

我将用单例编写一个示例,但我建议使用spring或容器等价物来实现这一点

public class Counter {
    private static Counter instance;
    private static int COUNT_MAX_VALUE = 1000000;
    public static synchronized Counter getInstance() {
        if (instance == null) {
            instance = new Counter();
        }
        return instance;
    }

    // -- end of static features --
    private int counter;
    public Counter() {
        this.counter = 0;
    }

    // return result
    public synchronized int getCount() {
        return counter;
    }

    // increment by 1, then return result
    public synchronized int addAndGetCount() {
        addCount();
        return getCount();
    }

    // increment by 1
    public synchronized int addCount() {
        if (++counter >= COUNT_MAX_VALUE) {
            counter = 0;
        }
    }
}

无法从你的问题中理解困难。在webservice调用中增加一个值并在达到某个限制时重置它似乎很简单,并且可以通过基本的条件运算符来完成。嗨,Joris,Spring如何使用,您能提供帮助吗?我不熟悉Spring,我的应用程序使用Spring框架。这是我无法帮助您的,这就是我给出单例解决方案的原因。如果您使用spring框架,那么有很多在线文档可供您阅读。我建议你仔细阅读你正在使用的框架。