How to set a timeout for a particular action in Java?

Asked

Viewed 249 times

0

I would like to set a timeout for a particular action on JSP pages, which should work with the following conditions below:

  1. When I click a button for example "Travel", the page should somehow save the start time and end time and tell how much time to reach a given destination.

  2. When I’m not on the page, time should continue.

  3. When I enter the page again, the page should show me how much time remaining to reach a certain destination from second to second.

Making use of this:

To determine how long the user will be able to perform the same action in the web application again, as there should be intervals.

  • 2

    Have you ever done anything? Post the code of what you already have or something close that you tried

  • I haven’t developed anything yet in relation to the timeout due to lack of knowledge of functions and ways to reach the goal according to the conditions cited.

  • Some points you need to set is, how will you identify if the person who left the screen will be the same as coming back. Do you plan to use session? will save something in bank?

  • possible duplicate of How to set a Java expiration time?

  • I will use session yes, and I will also save the hora_inicioand hora_final to compare on the page if you have already given the time... But when you do this comparison, I have to have the remaining time being displayed on the page from second to second, showing the remaining minutes without having to run a query second by second.

  • 1

    @I will be deleting the question cited, because many users are understanding that it is only a user session, and that is not it!

  • Hi Luiz Ricardo I think I know what you want! Still want to delete the question? I can try to help you. I think what you need is Websockets + a server-side session. Is that it? Websockets has these powers that you quoted.

  • Yes that’s right @Filipegonzagamiranda gave a read on the purpose of Websockets and that’s really what I want, now the challenge is to make use of this guy... You have knowledge of the use of Websockets, where I can find good content that explains ways to use?

  • @Filipegonzagamiranda do the following... answer the question with a link of ways to use Websockets, and then I will accept your answer as useful in relation to the question.

  • Sure! It is not very difficult to use. You will like the technology.

  • I will definitely go, I am researching in depth... I saw videos of use and I also saw what is capable... very interesting and I will also use a lot!

Show 6 more comments

1 answer

2


Hi @Luiz Ricardo Cardoso,

As we speak what you need is Websocket Protocol. A technology not only very fun but also powerful.

Here is the official link of the technology that is directly linked with HTML 5

https://www.websocket.org/aboutwebsocket.html

In this next link you will find an excellent documentation/tutorial using Spring MVC

Websockets with Spring MVC

Well, do you need something in English? Just got it!

English Material - Jetty + Java + Websockets

Is there any JSR for the use of Websockets in Java?

Yes: JSR 356

What are your characteristics of this JSR?

  • Annotated programming, allowing developers to use Pojos with the life cycles of Websocket events

  • Programming directed to interfaces (implement interfaces), allowing developers use Pojos with the life cycles of events
    Websocket

  • Integrating with other Java EE technologies - you can inject objects and Ejbs such as Contexts and Dependency Injection

Hope you Enjoy.

I can’t help but mention the client side! ;)

Take a look also at the Angularjs to build your application(it is not essential to know Angularjs, but maybe you find interesting).

  • 1

    Very good, that’s all and with additional! Solved the question, thank you.

  • 1

    Glad to know it worked, that’s the importance of the community! Sucesso @Luizricardocardoso !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.