Sequence number generation in Java [closed]









up vote
0
down vote

favorite
1












I need to generate a sequence number which is in ranges of 1000 to 3000. Every day at 12 midnight this sequence should reset to 1000 and for each request this should be incremented. Is there any way we can achieve this. I need to implementation in one of web application which uses Spring Boot and MongoDB.



I know in Java we cant achieve as my application will be run as multiple instance also it will be deployed in Cloud docker container.










share|improve this question













closed as too broad by Joakim Danielson, Roddy of the Frozen Peas, Graham, Devon_C_Miller, Rob Nov 10 at 2:03


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















    up vote
    0
    down vote

    favorite
    1












    I need to generate a sequence number which is in ranges of 1000 to 3000. Every day at 12 midnight this sequence should reset to 1000 and for each request this should be incremented. Is there any way we can achieve this. I need to implementation in one of web application which uses Spring Boot and MongoDB.



    I know in Java we cant achieve as my application will be run as multiple instance also it will be deployed in Cloud docker container.










    share|improve this question













    closed as too broad by Joakim Danielson, Roddy of the Frozen Peas, Graham, Devon_C_Miller, Rob Nov 10 at 2:03


    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
















      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      I need to generate a sequence number which is in ranges of 1000 to 3000. Every day at 12 midnight this sequence should reset to 1000 and for each request this should be incremented. Is there any way we can achieve this. I need to implementation in one of web application which uses Spring Boot and MongoDB.



      I know in Java we cant achieve as my application will be run as multiple instance also it will be deployed in Cloud docker container.










      share|improve this question













      I need to generate a sequence number which is in ranges of 1000 to 3000. Every day at 12 midnight this sequence should reset to 1000 and for each request this should be incremented. Is there any way we can achieve this. I need to implementation in one of web application which uses Spring Boot and MongoDB.



      I know in Java we cant achieve as my application will be run as multiple instance also it will be deployed in Cloud docker container.







      java mongodb spring-boot docker






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 21:07









      springbootlearner

      1951418




      1951418




      closed as too broad by Joakim Danielson, Roddy of the Frozen Peas, Graham, Devon_C_Miller, Rob Nov 10 at 2:03


      Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






      closed as too broad by Joakim Danielson, Roddy of the Frozen Peas, Graham, Devon_C_Miller, Rob Nov 10 at 2:03


      Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          1) To generate the sequence number, you can have the sequence value stored in a Mongo document and use findAndModify operation to increment it everytime. You might want to use the option that returns the modified document, to get the latest value.
          https://docs.mongodb.com/manual/reference/method/db.collection.findAndModify/



          2) To reset the value at midnight, you can use spring boot scheduling. You can annotate the method which would reset the value in the mongo document with @Scheduled and specify a cron expression to run at the exact time.



          Since the sequence is actually stored in the database, you should not be having issues with multiple instances of your application.






          share|improve this answer



























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            1) To generate the sequence number, you can have the sequence value stored in a Mongo document and use findAndModify operation to increment it everytime. You might want to use the option that returns the modified document, to get the latest value.
            https://docs.mongodb.com/manual/reference/method/db.collection.findAndModify/



            2) To reset the value at midnight, you can use spring boot scheduling. You can annotate the method which would reset the value in the mongo document with @Scheduled and specify a cron expression to run at the exact time.



            Since the sequence is actually stored in the database, you should not be having issues with multiple instances of your application.






            share|improve this answer
























              up vote
              1
              down vote













              1) To generate the sequence number, you can have the sequence value stored in a Mongo document and use findAndModify operation to increment it everytime. You might want to use the option that returns the modified document, to get the latest value.
              https://docs.mongodb.com/manual/reference/method/db.collection.findAndModify/



              2) To reset the value at midnight, you can use spring boot scheduling. You can annotate the method which would reset the value in the mongo document with @Scheduled and specify a cron expression to run at the exact time.



              Since the sequence is actually stored in the database, you should not be having issues with multiple instances of your application.






              share|improve this answer






















                up vote
                1
                down vote










                up vote
                1
                down vote









                1) To generate the sequence number, you can have the sequence value stored in a Mongo document and use findAndModify operation to increment it everytime. You might want to use the option that returns the modified document, to get the latest value.
                https://docs.mongodb.com/manual/reference/method/db.collection.findAndModify/



                2) To reset the value at midnight, you can use spring boot scheduling. You can annotate the method which would reset the value in the mongo document with @Scheduled and specify a cron expression to run at the exact time.



                Since the sequence is actually stored in the database, you should not be having issues with multiple instances of your application.






                share|improve this answer












                1) To generate the sequence number, you can have the sequence value stored in a Mongo document and use findAndModify operation to increment it everytime. You might want to use the option that returns the modified document, to get the latest value.
                https://docs.mongodb.com/manual/reference/method/db.collection.findAndModify/



                2) To reset the value at midnight, you can use spring boot scheduling. You can annotate the method which would reset the value in the mongo document with @Scheduled and specify a cron expression to run at the exact time.



                Since the sequence is actually stored in the database, you should not be having issues with multiple instances of your application.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 23:12









                Dexter

                363




                363













                    Popular posts from this blog

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Syphilis

                    Darth Vader #20