Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
So if user click on disable button should be some flag active for 24 hours that it is disabled and customers do not see the app, then it is automatically re-enabled so it is visible again.
I would like this may be to be a boolean, but not sure,
So is there any simple fix for this or I should control in page load if this true or false, but still I need this somehow to measure the hours, passing so I can show the user in the dynamic way how hours are left, Thanks, and I would appreciate any idea you might have.
In Spring,You can use #Scheduled annotation to execute a function periodically, even user hasn't done any click actions.
#Scheduled(cron = "0 0 12 * * ? 2019")
public void runIt(){
//write something to execute periodically
}
The above scheduler run At 12:00 pm (noon) every day during the year 2019.
For setting your own schedule you can refer
Scheduled
and
Cron params
Or
If you want call a method only after an action, you can use the Java Timer and TimerTask Classes refer this link Java Timer Task
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I need to implement a countdown timer for a quiz in a Spring boot webApp.I tried to implement it using JS but every time the user clicks on the next question button the timer resets. the timer must be of five minutes and at 00:00 the quiz must be auto-submitted.
In past I have implemented something similar, It was for learning purpose. On server-side I have created cookie for user and session, then I have stored start time in session for this user. So refreshing website would just pick up start time from user session kept on server. As for auto-submit functionality, you would need to implement It on the frontend side. Using JS you can check whether time has reached 00:00, and run function that performs submit.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a fast food app the one has to be disabled from 10.pm to 9.am, what I really need is to disable a button using UI local time format during that time and show an alert dialog base on the same principle I been searching for and nothing... please help and thanks.
You can get hour of the day using this:
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
HOUR_OF_DAY will give you 24-hour time. Then just check something like this:
if (hour >= 22 && hour <= 9) button.setEnabled(false);
Now there are few options to disable the button. You can use:
setClickable(false)
setEnabled(false)
setOnClickListener(null)
Notice that if you setOnClickListener(null) then you need to set your listener again if the time is correct.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to execute a method in a class say every day only once . If in a day already executed just return or else execute the method.
I want to know what happens if I exit the code will it be running in the background?
Assuming that you already know how to schedule a task to run daily
the trick becomes knowing if the task has already run in that day without being prompted by the schedule.
For the desired behavior you will need to save a time-stamp (either as a variable in the java environment or as a file on the disk) of the most recent run, checking it before updating it and executing the function.
Some psuedocode:
Static bool timeManager(){
CurrentTime = getCurrentTime()
TimeStamp = getTimeStamp()
if(CurrentTime - TimeStamp > 1day-afewMinutes){
UpdateTimeStamp(CurrentTime)
return true
}else{
return false
}
}
void jobWrapper(){
if timeManager(){
doTheJob()
}else{
log("Skipping job at "+currentTime+" because job ran "+lastTime)
}
}
Edit: rollback pointed out race condition so I put the time manager in a static method. Also I realized that rounding to the second might bone you so I figured I would subtract a few minutes from the whole day to avoid tasks scheduled on 24 hour intervals from blocking each-other due to rounding...
There are many ways to do this.
You can use sth like Cron job. The expression is guided here: https://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cron_expressions.htm
Or you can use Quartz: http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html
Or use #Scheduled from Spring https://spring.io/guides/gs/scheduling-tasks/
Hope this help.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've currently got a system with a user account and login system. I'm trying to implement a "lockout" function, so that after 3 incorrect password attempts, the user is locked out. Currently this only involves a popup window, and simply warns the user instead of locking them out. I'm trying to find a good way to do this, based around a timeout so after a set amount of time the user can try to access their account again.
One idea I have is to write the time of lockout to a text file, and then have the system check for the previous lockout time from this text file and allow login if enough time has elapsed, however this seems to be an inelegant way to solve this.
Is there any other ways that this could be done? thanks
Usually, you'll use a database with fields like
id
username
password
failedAttempts (int)
lastFailed (date)
lastLogin (date)
When they fail to login, you increment failedAttempts and save the time in lastFailed.
Then on login, you check if (failedAttempts < threshold) or ((now - lastFailed) > timeThreshold).
On login you reset failedAttempts = 0, and lastFailed = null
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm creating an app, which can show the times of different cities. I have an api which takes coordinates and gives me something like - America/Chicago. But I want to show this on a Digital Clock. Can someone please tell me how to change the timezone of a DigitalClock, or make a custom one. I have no clue! Thanks for the help!
Android: DigitalClock remove seconds
customized digital clock in android
I assume you can then work out how much time to add/subtract from the system's time to show the destination's time.
Do you mean by like a digital clock as in a widget? You're going to need to give more information about it.
You can try doing a textview in an activity and set it to change every minute or hour by getting the time from this class
from Android API.