Javabeans and concurrency

Javabeans use instance variables that represent the bean's properties with
          getter and setter methods. Are the bean's properties thread safe?
          If I create a bean and store it in a session, can I assume when I do a
          getter/setter on the property that there will not be concurrency issues? (I
          realize that session objects have issues with frames but I can ignore that
          for now).
          Any examples I have seen of using javabeans with JSP's do not use
          single-threaded and do not synchronize access.
          thanks.
          

Actually, we've just seen a case where a session scope bean
          was getting accessed concurrently by different threads, coming
          from a single browser window. We are using the Apache-Weblogic
          plugin, which at times will cause a failover retry on the same
          server on behalf of the same session, and so the same session
          scope bean will be used. Problem is, the failover retry should
          not have happened, since the server hadn't really failed, it was
          just taking a long time. This, I would think, is a bug in the
          Apache-Weblogic plugin mechanism.
          Anyway, the second retry attempt causes a new thread to
          assume the pre-existing session scope objects, which has
          to be a problem, in my book...
          Jason
          "WebLogic" <[email protected]> wrote in message
          news:[email protected]...
          > This is accurate except that in the session case, it is
          > really per set of browser windows. You can see concurrency
          > problems when more than one browser window is open
          > or when you use frames and share the JavaBeans in the
          > session.
          >
          > Sam
          >
          > "sumanth" <[email protected]> wrote in message
          > news:[email protected]...
          > > well it depends on the scope of the java bean.
          > > normally there are 3 sometimes 4 scope's for the beans
          > > page,request,session,application.
          > >
          > > the first 3 you will not run into any problem's as they
          > > are on a per page,per request,per user respectively.
          > > It is only when you use the bean as an application scope u
          > > should make sure that they do not have any instance variables ,
          > > if they have u should handle the synchronization.
          > >
          > > the above discussion is for beans.
          > >
          > > talking about jsp's in general...
          > > if you have any variables declared in the <%! %> (note the !)
          > > they are not thread safe as they are class variables. all jsp's by
          default
          > > DO NOT implement the singleThread Model (performance) but one can
          > > have thier jsp's implement the single thread model by having this
          > directive
          > > on the top of the page
          > > <%@page isThreadSafe="false" %>
          > >
          > > -Sumanth
          > > "JOG" <[email protected]> wrote in message
          > > news:[email protected]...
          > > > Javabeans use instance variables that represent the bean's properties
          > with
          > > > getter and setter methods. Are the bean's properties thread safe?
          > > > If I create a bean and store it in a session, can I assume when I do a
          > > > getter/setter on the property that there will not be concurrency
          issues?
          > > (I
          > > > realize that session objects have issues with frames but I can ignore
          > that
          > > > for now).
          > > >
          > > > Any examples I have seen of using javabeans with JSP's do not use
          > > > single-threaded and do not synchronize access.
          > > > thanks.
          > > >
          > > >
          > >
          >
          >
          

Similar Messages

  • What is the diffrence between a javabean and  EJB

    hi!
    what is the diffrence between a javabean and entreprise jvaabeans! i mean which are the uitilization featires of eaxh one !

    i am seeking for a solution for my problem , in fact i ma trying to implement and develop an application with java that allows a certain range of IP adresses to be connected to a database server in order to extract the suitable data from the server .
    let me explain mor ethe suitation , in fact what i am loking for is to use javabeans to grant my application much more consistence and pertinence : si i am asking if it could be possible to use javabeans in my case especially if i am not trying to developp a web application but a cleint /server one allowing some services.
    The application is in fact dealing with a stock exchange market and what i am trying to do is to grant particilar registrated customers to have the informations that they need ( portofolio, currency's status, market indicators, .) also drawing some charts decribing rates, variations, and others specefic financial caracterestics .So , if we consider that this application is not a web application ( no HTTP request and no servers like apache or others ) how it is possible to use javabeans and not EJB to build the application? i mean what could be suitable and preferable to rely on and dvelop to ensure a good java application !!
    if you need more details to help you find the answer for me don't hesitate to answer me back !!
    Someone here gave me that answer
    use RMI to code the services and (Updateable) Value Objects to pass the information between tiers.
    RMI is an all-java distributed component framework (ie. EJB, CORBA, DCE/RPC, DCOM, etc.), that is very suitable for developing non-containerized multi-tier applications. Refer to the RMI trail in the Java Tutorial as a starting point for coding RMI solutions (http://java.sun.com/docs/books/tutorial/index.html). Under this scenario you would code the database access service as an RMI service (server-side). Client/server communication should be facilitated through the use of JavaBeans/classes that wrap the information being passed (customer information, portfolio details, market information, etc.) - these are refered to as 'Updateable Value Objects' (a design pattern). Graphing and charting would be handled in your client from the information received from the (RMI) server. GUI JavaBeans can be used to provide this functionality as well as other client-side services. There are numerous "shrink-wrapped" components for GUIs available on the market just peruse any Java magazine to find them.
    but how comes? how can i do it !! and where can i find more information please about 'Updateable Value Object "
    thanks

  • What is a javabean and how to compose it?

    Q1:although have used many java class in jsp within tomcat, but i don't is it a standard javabean. I mean is any java class can be an javabean, or what is the different between javabean and java class.
    for now i found some problem with 'javabean' used in jsp.
    Q2:what is ther difference between use jsp:setProperty,jsp:getProperty and direct give value like 'myBean.variable=100'?
    thanks!

    javabeans are standard classes but have :
    - default constructor
    - getter and setter methods
    javabean can be used on custom tags, so no code on your jsp !
    why don't directly use attributes ?
    look this thread :
    http://forum.java.sun.com/thread.jsp?forum=45&thread=314643
    this is one, but it's not the only, reason.
    Regards.

  • Using JavaBeans and not use BDK?

    I sort of understand Java Beans and currently writes custom beans for my installer using InstallShield MultiPlatfor Edition. I do register the bean(s) the same way as you do with BDK.
    Are there any samples or documentation so that I can write my own GUI builder so I can drop the beans there
    just like you do in Visual Cafe, Visaul Age for Java and JBuilder?
    Or we write JavaBeans and be at the mercy of BDK and or 3rd party GUI builders?

    Do you actually need a GUI builder for your beans??
    In my experience GUI builders are rarely useful and when they are useful it's usually for only the simplest of examples.
    Why not simply code them by hand using the beans' documentation? You'll actually learn something instead puzzling over the myriad shortcomings associated with GUI builders.
    This is not to say you shouldn't roll your own gui builder. But is that really where you should spend your time?

  • JSP JavaBeans and Database

    i am wondering whats the "correct" or best way to connect to a DB using JavaBeans and using this in JSP pages?
    i read abt creating a SQL "Helper" class that has some functions like connect etc... but i am thinking its a bit confusing...
    if i have a function
        public static Statement Connect() {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                con = DriverManager.getConnection("jdbc:odbc:auction","","");
                stmt = con.createStatement();
            } catch (SQLException e) {
                System.out.println("ERROR: SQLException occured!\n" + e.getMessage());
            } catch (Exception e) {
                System.out.println("ERROR: An Exception occured!\n" + e.getMessage());
           return stmt;
        }then i use it
    Statement stmt = SqlHelper.connect();when i want to close the connection how do i do it? is it a must to close connections anyway?
    or shld i do it the easy way, having the code
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection("jdbc:odbc:auction","","");
    stmt = con.createStatement();on all JSP pages?
    Thank you

    BalusC wrote:Do it in the data layer. Write DAO classes and SQL helper classes. Then let the business layer, the Servlet, interact with the data layer and let the presentation layer, the JSP, display the results.
    And don't return a Statement, but a Connection. And yes, closing a Connection is a must, otherwise you're leaking resources which will cause your web application to crash due to a memory shortage.ya thats what i am trying to do... but how do i? like this? except i return a connection instead? and also, i shld return it by reference? mmm... in java isit like return &con?
    package AuctionSystem;
    import java.sql.*;
    public class SqlHelper {
        private static Connection con;
        private static Statement stmt;
        public SqlHelper() {
            Connection con = null;
            Statement stmt = null;
        public static void Connect() {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                con = DriverManager.getConnection("jdbc:odbc:auction","","");
                stmt = con.createStatement();
            } catch (SQLException e) {
                System.out.println("ERROR: SQLException occured!\n" + e.getMessage());
            } catch (Exception e) {
                System.out.println("ERROR: An Exception occured!\n" + e.getMessage());
        public static Connection getCon() {
            return con;
        public static Statement getStmt() {
            return stmt;
        public static void Close() {
            con.close();
            stmt.close();
        public static String FormatString(String string) {
            return "'" + string + "'";
    }Edited by: iceangel89 on May 27, 2008 3:50 AM

  • Weak and concurrent hash map for caching

    Hello,
    I have written a very simple cache class with both weakness and concurrency benefits. This class is intended to be used as a weak cache in "hot redeploy" capable servers (JBoss or any other).
    My implementation uses the (problematic) "double-check" pattern with a reentrant lock and encapsulates a WeakHashMap with WeakReference values (to avoid circular key/value references). Here is the code:
    public interface ValueCreator<V> {
         public V create();
    public class WeakCache<K, V> {
         private final Lock lock = new ReentrantLock();
         private final Map<K, WeakReference<V>> weakMap;
         public WeakCache() {
              this(16);
         public WeakCache(int initialCapacity) {
              this(initialCapacity, 0.75F);
         public WeakCache(int initialCapacity, float loadFactor) {
              weakMap = new WeakHashMap<K, WeakReference<V>>(initialCapacity, loadFactor);
         public V get(K key, ValueCreator<V> creator) {
              WeakReference<V> ref = weakMap.get(key);
              if (ref == null) {
                   lock.lock();
                   try {
                        ref = weakMap.get(key);
                        if (ref == null) {
                             ref = new WeakReference<V>(creator.create());
                             weakMap.put(key, ref);
                   } finally {
                        lock.unlock();
              return ref.get();
         }One usage of this cache is for session ejb3 lookup:
    private static final WeakCache<Class, Object> LOOKUP_CACHE = new WeakCache<Class, Object>();
    public static <T> T lookup(final Class<T> serviceClass) {
         T service = (T)LOOKUP_CACHE.get(serviceClass,
              new ValueCreator<Object>() {
                   public T create() {
                        String lookup = "myapp/" + serviceClass.getSimpleName() + "/local";
                        try {
                             return (T)(new InitialContext()).lookup(lookup);
                        } catch (NamingException e) {
                             throw new RuntimeException("Could not lookup EJB " + serviceClass + ": " + lookup, e);
         return service;
    ...2 questions:
    1. Is there any issue with concurrent access to this cache ?
    2. What happens exactly when the garbage collector wants to free memory with a map with both weak keys and values ?
    Some limited tests show that the behavior of this cache fits my needs: the lookup cache is cleared on redeploy and it keeps its key/values pairs otherwise.
    Thanks for any comments.
    Message was edited by:
    fwolff999

    I know that DCL is broken under certain circumstances (but I have read it may work with modern JVM and the use of volatile variables for example).
    So: is it broken with this specific implementation and if so, what should be done to make it work ?
    The getter method is potentially setting a value (like in ConcurrentHashMap.putIfAbsent) and it uses a ValueCreator in order to actually create the value only if it is not already present in the map.

  • RMI and concurrency (newbie)

    Hi
    I have a simple question related to RMI and concurrency.
    I have a server and several clients calling remote objects concurrently.
    How is concurrency usually handled when one used RMI ?
    Can we make use of "synchronized" on some method of the remote objects ?
    I have read about risk related to performance and worse, some problems of deadlock if the synchronize is not well organized.
    Is there other ways to deal with that ?
    Thanks in advance for providinge me any information or suggestion.

    RMI is inherently multithreaded. If you have specific remote resources that you want protected from concurrency, then define all of the accessor methods to be synchronized. (I don't think you can get away with making the remote methods synchronized; I would instead figure out what which resources I want to protect, and only protect those particular objects.)
    Could there be problems? Maybe. But these are absolutely standard coding techniques.

  • Difference between multiple employment and concurrent employment

    hi,
    What is the difference between multiple employment and concurrent employment.
    Regards,
    Chandra

    Hi
    Multiple employment is one person working woth more than one company with different EE iD.
    Person who has more than one personnel assignment with one enterprise or several affiliated enterprises in an cocurerent employee.
    Please go thru the link.
    http://help.sap.com/saphelp_47x200/helpdata/en/54/f535c614aa7a46800915c6f0dbc071/frameset.htm
    Ravee
    +91.99206.33669

  • How to create a thread safe and concurrent web part

    Hi,
    I am creating a sharepoint web part. 
    The web part will store the information in the sharepoint list.
    The web part is going to be used by 300 users all at the same time at the same moment.
    Each 300 users  trying to update list clicking button on my web part almost every 20 seconds.
    I am worried will the sharepoint List be able to handle so many concurrent updates.
    How should I design my webpart so that such issues do not arise and my webpart is also fast.
    Regards
    Vinod

    Hi,
    Per my understanding, there might be a concern about the performance and concurrent operation in your Visual Web Part.
    By default, there is already a built-in system in SharePoint handling the concurrent operation in a list, if the workload is not so high, it would be OK for the commonly use in
    your scenario.
    If there would be a requirement about creating a “fast” web part,
     a possible solution can be like this:
    In the web part, users click button to submit the specific update requirements with some data to server. In server side, we can create an application to handle the requests(add/update/delete
    item) from users sequentially one after one.
    By doing this, in client side, the web part will only responsible for submitting user request with simple data, all the time consuming jobs will be split into small tasks and being
    executed sequentially in server side.
    Also, here are two links below about some useful tips in developing web part which would be helpful to you:
    https://msdn.microsoft.com/en-us/library/dd583135%28v=office.11%29.aspx?f=255&MSPPError=-2147217396
    http://apmblog.dynatrace.com/2010/03/18/how-to-avoid-the-top-5-sharepoint-performance-mistakes/
    Thanks
    Patrick Liang
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • What is Enterprise JavaBean and Servlets?

    Hi there..
    I got kind of confused about enterprise JavaBean and Servlets.
    Are there examples for them to help me understand each of them
    Could someone kindly enlighten me. Thank u
    AG

    Keep a bookmark to http://java.sun.com/j2ee/tutorial/1_3-fcs/index.html

  • Named and Concurrent users

    Dear Friends,
    Please help me to find named number of users in PeopleSoft specific to module.Below are the modules i am using and i wanted to know named and concurrent users using these modules
    Human Resources
    Benefits Administration
    Pension Administration
    Thanks
    Uday.

    Hi Bart,
    Difference between named users and concurrent users:
    Named user means when you buy BOXI you buy a certain amount of named user licenses and then you give each of these named users a login. It`s a cheaper type of license but you have to know exactly who your users are, and so is pretty useless if your userbase is constantly changing or your exposing Infoview over the web.
    Concurrent user licenses are now only available in BOXI Edge - the equiv in BOXI Pro\Premium is a CPU license, which means you can let as many people login as your hardware will support. Concurrent user licenses are useful when you don`t know who your userbase is - you can just give a generic login for people to use. Or give people specific logins and not worry that they might not be using the system and using up a valuable named user license.
    for more information follow the below links:
    http://www.forumtopics.com/busobj/viewtopic.php?p=476977
    http://www.forumtopics.com/busobj/printview.php?t=125096&start=0&sid=095882f7c0d636e7bca723e5930c21d3
    Hope this helps.
    Regards,
    Deepti Bajpai

  • JavaBeans and EJB Difference

    Hi Experts:
    Can anyone tell me DIFFERENCE between JAVABEANS and ENTERPRISE JAVABEANS? I am a newbie to JavaBean world. How do we know which one to use when?
    Also, any startup BASIC TUTORIAL Link would be appreciated.
    Thanks!

    A javabean is simply a class that, through established conventions, exposes certain elements as standard properties. See http://developer.java.sun.com/developer/onlineTraining/Beans/beans01/ and http://developer.java.sun.com/developer/onlineTraining/Beans/beans02/ for a tutorial. Javabeans are a common part of most java programming.
    An enterprise java bean (EJB) is a heavyweight, transactional, remotable component running in a managed "container." EJB has little or nothing to do with regular javabeans. Use EJBs to build web applications and web services with steep scalability, failover and transactional requirements. See http://www2.theserverside.com/books/masteringEJB/index.jsp for a lengthy and comprehensive tutorial.

  • What is relationship between javabeans and Ejb ?

    I am new to javabeans and Ejb .
    thanks in advance.
    zzl_hz_cn

    nada. null. nil. void. zero. zilch.

  • Javabeans and Forms

    Are there any white papers or documentation that teaches how to create and use a javabean in Oracle Forms? I've looked at a couple of the demos but most of the documentation just seems to describe the PJC or javabean and none of the demos seem to work on the link http://www.oracle.com/technology/sample_code/products/forms/index.html. Also, the demos for 10g rel 2 are still not available. For us developers with only a little or no java knowledge the task of understanding how to use this technology with forms is pretty discouraging

    Hi Francois,
    I've looked at this site and it's pretty good and I think I might be able to get an existing bean working. The problem is that I have several developers on my project with essentially no java experience (they've taken a java class but haven't written anything outside of the class) and I'd like to get them started using this technology. How did you get startred? Some of my developers will be attending an Oracle University Forms class in mid April, but based on the class summary it doesn't appear that they even teach anything about javabeans.

  • Javabeans and EJB

    hi
    I am new to EJB and i have not worked on javabeans...
    My question is very basic... what is the difference between javabeans and EJB other than EJB running on a container and javabeans in jvm?
    Thanks for your help

    That's it in a nutshell, isn't it? EJBs require a J2EE container, and JavaBeans are components that follow the JavaBeans spec and run in a JVM.
    But think about all that the "container" means and all the services it provides. That's all the difference in the world.
    %

Maybe you are looking for

  • How can i get all these values in single row with comma separated?

    I have a table "abxx" with column "absg" Number(3) which is having following rows absg 1 3 56 232 43 436 23 677 545 367 xxxxxx No of rows How can i get all these values in single row with comma separated? Like output_absg 1,3,56,232,43,436,23,677,545

  • Help with determining next Saturday of the week in GMT

    Hi All, Here's a quick newbie question: What's a quick way to determine the next Saturday of the week in GMT? Thanks!

  • How to display document from external archive via archivelink?

    Hi, I would like to display in SAP (via ArchiveLink) scanned document which was stored in an external archive (FileNet). The archive system is connected to SAP via ArchiveLink. However the scanned document isn't stored in the archive system via SAP s

  • Refferencing something in a different class?

    hi im new to java and this has pretty much completely halted my progress, this is probably a pretty simple question but if someone could help me out i would really appreciate it say i have public class namething      public String name;      public n

  • Problem viewing I-Tunes 8

    When viewing I-Tunes 8, the music library list background is purple and the left hand menu bar is very dark gray, making it almost impossible to read. If I click on the full screed icon, it goes back to white but only until I do something else. Does