Content Management and Capture

 View Only
Expand all | Collapse all

Is it possible to share a CMBItem across threads?

  • 1.  Is it possible to share a CMBItem across threads?

    Posted Tue September 07, 2021 12:24 PM

    I develop an application that works with Content Manager classes.

    I know from the documentation that it is not possible to share a single CMBConnection instance by multiple threads:

    "A single instance of the CMBConnection bean can only be used on a single thread at any point in time." (link)

    Hence, the threads in my application use the CMBConnectionPool to get and release connections.

    Because of the application design, it would be beneficial to be able to share CMBItems across threads, e.g.:

    1. [thread-1] Uses CMBQueryService and CMBSearchResults to fetch some CMBItem from the server. The CMBItems are then added to a queue for further processing;
    2. [thread-2] Takes one item from the queue, calls cmbItem.setConnection(thread2Connection), and does some work with the item (like downloading it's contents).

    Even though I'm replacing the CMBItem's connection by the one that's exclusively used by thread-2, I was able to see in a profiler that thread-2 is still blocked by resources owned by thread-1. I concluded then that replacing the CMBItem connection is not enough. Actually, this old support page states exactly that:

    "The APIs do not directly support multiple threads using the same connected session and the objects obtained from that connected session." (My emphasis added)

    That support page only applies for CM 8.1 and 8.2, though. Is there a way of sharing CMBItem instances across threads in CM 8.5 or 8.6? Is there any other objects apart from CMBConnection that I need to replace in the bean?


  • 2.  RE: Is it possible to share a CMBItem across threads?

    Posted Tue November 16, 2021 10:31 PM


    Beans does not support this. You can implement it with other solutions, eg:deep copy a CMBItem in thread-2.