• Post Reply Bookmark Topic Watch Topic
  • New Topic

Two sequences of background operations on the same set of resources intertwining

 
Jake Kowalski
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In my Android application, the user logs in and then in the background the following stuff happens:

network request to server
parsing objects
saving objects to db
setting local notifications (hundreds)
creating calendar events (hundreds)

Then the user logs out, and this is what happens:

network request to server
deleting local notifications
deleting calendar events
deleting database

If the user logs in and then logs out, somewhere along the middle of the first sequence of actions, the seconds sequence of actions starts as well and a complete havoc is the result, typically a Null Pointer Exception.

How do I control this? Do I use a globally accessible operation Semaphore and obtain it at the beginning of each sequence and release it at the end, so the next one starts using it, or do I check for user log out process or schedule download process inbetween each step of the sequence?


A sequence in my case is something like this:

class A calls classes B, C, D and waits for each one to finish, using listeners.
I want a sequence to be atomic, before another sequence is started.


 
L Foster
Ranch Hand
Posts: 202
11
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Jake, Hello.

If these are required to be atomic, I would find a way to avoid letting the user complete a login until all the logout sequence is complete, and vice versa. It sounds like login takes more than trivial time. If it were me, I would aim to make that time as short as possible, first. Likewise for logout.

Then, yes, I would do some kind of account locking. I would make that a semaphor (or transaction, or whatever) covering the whole operation. If you can do a transaction that covers all those sub-operations, that would be ideal, IMO.

Sometimes, even though we strive to make users eat as little data as possible, some wastage will have to happen. Just as an aside, what would happen if you left your accounts "always logged in"? Fat data left around? Massive resources open? Just a thought.

HTH
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!