2 Replies Latest reply on Mar 2, 2008 2:15 PM by Matthias Gladt

    Concurrent Threads in Seam components

    Matthias Gladt Newbie


      Is it possible to access injected objects from two concurrent threads e.g. like

      public Component implements Runnable {
        private User user;
        private cacheUpToDate = false;
        public void checkCache() {
            if(!cacheUpToDate) {
              Thread t = new Thread(this);
        public void run() {
        pivate void loadSomeData(User user) {
        // load some user related data in background

      and then e.g. call 'checkCache()' from pages.xml every time the page is loaded?
      I got NullPointerExceptions whenever I was trying to access an injected component.
      Is there a solution to this problem?

        • 1. Re: Concurrent Threads in Seam components
          Keith Naas Novice

          Is the NPE occuring on a reference to the user object?

          Since its not really participating in Seam context, user is likely not available since injection doesn't occur.

          For caching you might try the
          PojoCache component.

          For asynchronous loading of the user data, see the section on 18.1.1. Asynchronous methods

          You can even schedule it with @Duration, @Expiration and @IntervalDuration annotations for more flexibility.

          Also not the following:

          bq. The asynchronous method is processed in a completely new event context and does not have access to the session or conversation context state of the caller.

          You could put the asynchronous method in an event scoped component and then inject it into your Session object.

          There may be some examples of the cache and asynchronous in the seam examples.

          Good luck!

          • 2. Re: Concurrent Threads in Seam components
            Matthias Gladt Newbie

            Hi Keith,

            Thanks a lot for your response! @Asynchronous offers some additional cool features. I still have to think of a way to set my scopes in an appropriate way, but that's rather a design issue.