Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

How to properly work with thransactions on a thread executor?

Hi I have something like this:

@EventDriven
@TransactionalEvent
@Notify(fifo = true)
@NotifyType(write = true, update = true)    
class MyClass {
   @GigaSpaceContext
   private GigaSpace space;
   private final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
   ....
   @SpaceDataEvent
   public void processEvent(final MyEvent event){
       Task task = new Task()
       executor.schedule(task, 100, TimeUnit.SECONDS)
   }

   private final class Task {
       public void run(){
           space.read(....
           space.write(....
       }
   }
}

How you properly work with the space inside the run() method in transactional manner? Thanks, Luke

asked 2014-04-30 02:46:29 -0600

lukeh gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

Any reason why you start a new thread within the processEvent method? It is triggered via a dedicated thread (notify thread). Is your task is a long running one? That's the only reason why you should place your logic into a different thread as it will release the notify thread.

Any way - you can start a transaction manually: http://docs.gigaspaces.com/xap97/tran...

Get the PlatformTransactionManager once.

Shay

answered 2014-04-30 08:07:41 -0600

shay hassidim gravatar image
edit flag offensive delete link more

Comments

I need to implement sort of a timers. I want to start actual processing of the event at a timestamp coming as a field of it. That timestamp may need to be hours later, other similar events may come meanwhile, but the job within run() is pretty short. Edit: also the timestamp may change and the task canceled and rescheduled in that case on the update event. I tryed using programmatic transaction having this at the beginning of run():

GigaSpace space = new GigaSpaceConfigurer(ijSpace).gigaSpace();
PlatformTransactionManager ptm = new LocalJiniTransactionManager();
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
TransactionStatus status = ptm.getTransaction(definition);
...
space.read()

ijSpace obtained from the GigaSpace instance in MyClass or instead of that first line using directly that instance or another anotated on inside Task class. In all the cases it hanged when reaching read/write methods.

EDIT: just noticed the get ptm once. I tested with only one run trough that method so unless I did something else wrong it is once.

lukeh gravatar imagelukeh ( 2014-04-30 08:30:57 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-04-30 02:46:29 -0600

Seen: 90 times

Last updated: Apr 30 '14