Java-backed Web Scripts Multithread

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2011 06:37 AM
Hello,
I have a Java-backed Web Script (like this example: http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples#SimpleWebScript.java)
Are java webscripts already prepared for multithreading?
Or I have to put something in the <bean> configuration? Or I have to program the java class for multithreading?
In other words, is created a new object of the WebScript java class for each request or is a Singleton?
Thanks a lot!
I have a Java-backed Web Script (like this example: http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples#SimpleWebScript.java)
Are java webscripts already prepared for multithreading?
Or I have to put something in the <bean> configuration? Or I have to program the java class for multithreading?
In other words, is created a new object of the WebScript java class for each request or is a Singleton?
Thanks a lot!
Labels:
- Labels:
-
Archive
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2011 06:42 AM
By default Webscripts are declared as singletons.
If you need for a single request a new instance of the WebScript you have to declare the attribute singleton="false" in the Spring bean definition. But I never tried to use a prototype for a WebScript, I don't know if there are some issues for this.
Hope this helps.
If you need for a single request a new instance of the WebScript you have to declare the attribute singleton="false" in the Spring bean definition. But I never tried to use a prototype for a WebScript, I don't know if there are some issues for this.
Hope this helps.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2011 06:56 AM
But I think that even declaring this attribute, if the object that creates webscripts is a Singleton, and only creates the webscript once at the begining (not one for each request), and then uses the same object, this attribute will be useless.
Am I right?
That's a fast reply! Thanks so much.
Am I right?
That's a fast reply! Thanks so much.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2011 09:24 AM
See http://static.springsource.org/spring/docs/1.2.x/reference/beans.html
If you declare a spring bean as not a singleton then for each invocation a new instance is created and destroyed.
I doubt that this is ever required for a web script. If you are considering using it, I suggest you think again. Or post your use-case so we can debate.
If you declare a spring bean as not a singleton then for each invocation a new instance is created and destroyed.
I doubt that this is ever required for a web script. If you are considering using it, I suggest you think again. Or post your use-case so we can debate.


Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2011 10:53 AM
My use case is:
1- Obtain a document (using the object ServiceRegistry.getContentService.getContentReader)
2- Using the document's data, create another document in the same folder as the original one
3- Save new data in the document created (using ServiceRegistry.getContentService.getContentWriter)
I'm interested in multithreading because I don't know if these Alfresco Interfaces (ServiceRegistry, ContentService, ContentReader and ContentWriter) are ready for it.
1- Obtain a document (using the object ServiceRegistry.getContentService.getContentReader)
2- Using the document's data, create another document in the same folder as the original one
3- Save new data in the document created (using ServiceRegistry.getContentService.getContentWriter)
I'm interested in multithreading because I don't know if these Alfresco Interfaces (ServiceRegistry, ContentService, ContentReader and ContentWriter) are ready for it.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2011 11:43 AM
You have no class level "state" in the above use-case, so thread safety is not an issue. The interfaces you are calling are all "thread safe" there will not be a problem.
However as an asside I'd avoid using the ServiceRegistry, there's no need for it if you inject your dependencies.
However as an asside I'd avoid using the ServiceRegistry, there's no need for it if you inject your dependencies.
