R
R
reus2018-06-20 01:57:38
Java
reus, 2018-06-20 01:57:38

How to make simultaneous processing of different in one transaction?

Hello. I came across an interesting problem for me related to transactions, maybe someone will tell you.
The task is to track the number of user visits and the duration of visits.
There is a web application (now on spring). It has a mini api with one controller that multiple users knock on.
There are different options for user behavior:
1. Optimistic . The user can knock and after the door opens he can enter. To exit, he must knock again - the door lock will open and he then exits.
2. Regular. When trying to enter / exit, the user can knock one, two, three times, then the door will open and only after that he will actually be able to enter / exit.
3. Difficult situation . User "A" can knock to enter, the door will open, and user "B" will exit and after that only "A" will enter (of course B did not knock and how would we track that he left without knocking).
4. Life is pain . The user can knock - the door will open, he comes in staggering either leaving or entering, but in the end he will most likely enter (the same exit behavior). In this case, you need to save the first "input" and the last "output" of the user in the visit.
The problem is that each request comes in a new thread.(servlet-api without asynchrony) and each request is processed in the service in a special "way" in one transaction and in the end a "visit" is created and a record with the user's entry / exit is attached to it. Are there any recommendations on how to make sure that when processing a request, all user shuffles are tied to a visit and at the same time do not create unnecessary visits and do not post-process visits (for example, every 5 minutes with quartz or an analogue)?
I apologize in advance for the "many letters"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Cr2ed, 2018-06-20
@Cr2ed

And from the client to send a message that I (the user) has logged in and I'm still active is not an option?
If you forgot to log out, then such a message will not arrive.

A
Alexey Cheremisin, 2018-06-20
@leahch

As for the duration of the visits, I wouldn't recommend it here. But for the number of visits, please.
When you first visit the site, put a supercook for it, for example, for a month, or for a year.
1) Read the supercookie, or generate it if there is none
2) Forward this supercookie to all logs.
3) When processing logs, we look for an object with this supercookie and fill it with information who, when, under what name. which browser or client, etc. Associate the user with the supercookie.
In other words, we have both a supercook and a user, and it doesn't matter here whether he logged in, logged out, moved somewhere, etc.
PS. As for the time spent on the site, make an ajax timer that works out 5, 10, 30 seconds and 1, 3, 5 minutes, knocking on the endpoint, and the supercook will be included with the request. In this way, you can even catch bots that work without JS (which are also caught with JS),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question