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

  • SEARCH
  • Home
  • 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 7904811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:14:52+00:00 2026-06-03T10:14:52+00:00

I am currently into the development of a play-powered (v. 1.2.4) application where users

  • 0

I am currently into the development of a play-powered (v. 1.2.4) application where users can perform certain tasks and gain rewards for doing so. These tasks require some energy, which will be refilled over time. The basic setting is as follows:

public class User extends Model {
    public Long energy;
    public Long maxenergy;
    public Long cooldown = Long.valueOf(300);
}

public class Task extends Controller {
    public static void perform(Long id) {
        User user = User.findById(id).first();

        // do some complex task here...

        user.energy--;
        user.save();
        Task.list();
    }
}

Now I want to refill the energy of the user after the cooldown (5 min). Assuming the user has 10/10 energy points and I want to refill a point 5 minutes after it has been used, I could easily use a job for this:

public class EnergyHealer extends Job {
    public Long id;

    public EnergyHealer(Long id) {
        this.id = id;
    }

    public void doJob() throws Exception {
        User user = User.findById(id);
        user.energy++;
        if (user.energy > user.maxenergy) {
            user.energy = user.maxenergy;
        }
        user.save()
    }
}

… and call it in my controller right after the task has been competed:

new EnergyHealer(user.id).in(user.cooldown);

My problem here is, that in this case jobs are scheduled concurrently, thus if the user performs a task 2 seconds after he performed a previous task the first energy point is refilled after 5 mins, while the subsequent point is refilled only 2 seconds later.

So, I need the jobs to be serialized, e.g., assuming I have 8 of 10 energy points, it should take exactly 10 minutes until all energy points are refilled.

On a related note: users have different levels and gain experience for completing tasks, once a certain threshold is reached. Their level is increased and all energy points are refilled, no matter how many of them have been used in the previous level, hence some jobs may become obsolete by the time they are executed.

Considering some thousand users, jobs may not be the perfect choice at all, so if someone has an idea on how to achieve the described scenario, I’m glad for any help!

  • 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-06-03T10:14:53+00:00Added an answer on June 3, 2026 at 10:14 am

    I think you just have your Job scheduling wrong. Rather than kick off your job every time they perform an action, you should simply have a facade or something that will only kick off a job if one does not already exist for the user.

    1. If the job does not already exist, create it, otherwise do nothing

    2. then this should add 1 energy,

    3. check if energy is full, if it is, end

    4. if not, pause for 5 minutes

    5. go back to 2

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

Sidebar

Related Questions

I'm currently looking into automating a flex build so that we can get it
I am fairly new to XCODE development currently following several tutorials. Bumped into an
Our development team is currently looking into migrating our search system to Apache Solr,
Currently i am trying to get into jQuery and jQtouch for the development of
I'm currently in the development process of an application which needs to be able
I am pretty new to iPhone development and currently working on an application which
I'm currently working my way through the book Teach Yourself Android Application Development in
Recently I've been getting more and more into mobile development. I am currently working
Im currently looking into the difference between IBM Websphere Application Server and IBM Websphere
I am new into Facebook application development and also newbie about JavaScript and PHP

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.