Java: race conditions - is there a way to make sure multiple lines of code are executed together?

I have a registration page that receives tokens, analyzes them and enters the user’s system if the parameters are applied.

Meanwhile, when I checked the token, by the time I removed the token from db, another user can use the same token to enter. is there any way to make sure that a certain range of lines of code will be executed without intervention, so I will not have a problem with the state of the race?

thank

Update

I have two servers.

  • apache tomcat 6
  • red5 v0.9 (free Java streaming media streaming and communication server)

I am writing a Facebook application.

The game itself is written in Adobe Flash Builder 2.

red5. , red5 - , facebook.

, tomcat, facebook tinyFBClient facebook mysql db ( ), , red5.

. tomcat HTML , SWF ( ). tomcat SWF . SWF red5 .

, . !

+3
5

Lock.

Lock .

+2

, . , . , .

? , .

+3

, . , , , , . , , " ".

, , ? , , , , , , , . ?

+2

, " db". SQL? , , . :

  • , . UUID sessionID = UUID.randomUUID();
  • , , , ,
    DELETE FROM Tokens WHERE TokenID = < request-token >
  • , , 1, . , ,
    INSERT INTO Session VALUES (sessionUUID, userID, loginTime,...)

, (.. 1), cookie, .

+1
source

Source: https://habr.com/ru/post/1731867/


All Articles