Rendering of component tree might not be thread-safe

I'm using JSF implementation 1.1_01 and noticed following problem. Rendering simultaniously the same JSF - page in two different browser session (browsers even running on different workstations) results in corrupted html pages.
If you are "lucky" you find the complete normal html code in one browser and the rendered jsf tags twice on the other screen. Sometimes the mixture is minor, sometimes both clients get their pages complete.
I'm using the server state setting.
Anyone noticed a simular behaviour?

Yes, I used tiles.
first try was like this pattern:
<f:view>
<f:subview id="head">
<t:insert attribute="head"/>
</f:subview>
<f:subview id="body">
<t:insert attribute="body"/>
</f:subview>
</f:view>
The result was a correct rendered head-tile and a strange rendered body-tile, where jsf-tags are rendered first and the html tags second.
So I head to insert <f:verbatim> tags around all html-tags to get it rendered correctly. Looked very ugly. After doing that, I noticed that I didn't receive any events when I click on any button in a subview.
After serveral attempts I came to the following, wrong example:
<f:view>
<f:subview id="head">
<t:insert attribute="head"/>
</f:subview>
<f:view>
<t:insert attribute="body"/>
</f:view>
</f:view>
This really should not work. It is wrong. But it did and all tiles were rendered correctly even without verbatim. But... It only worked for a single user system. Doing perfomance tests with serveral simultated users, I noticed that the JSF-Tags output was mixed up in differnt sessions. Can't blame anyone for that. the usage was incorrect, but it might be interesting to do performance tests for subviews to see if there are problems with multiple simultanious requests too.
My decision: I take an old fashioned approache with static jsp includes. It might be ugly, but it works as expected.

Similar Messages

  • Vector is not  a Thread safe so where be use it and why?

    Can anyone tell me
    When Vector is not a Thread safe so where be use it and why?

    Suppose you use a Vector<Listener> to store your list of listeners. While the Vector class is thread-safe, which means that its methods can be called without additional synchronization without risk of corrupting the Vector data structures, iterating a collection involves "check-then-act" sequences, which are at risk of failing if the collection is modified during iteration. Let's say there are three listeners in your list at the start of iteration. As you iterate through the Vector, you repeatedly call size() and get() until there are no more elements to retrieve, as in Listing 1:
    Listing 1. Unsafe iteration of a Vector
    Vector<Listener> v;
    for (int i=0; i<v.size(); i++)
    v.get(i).eventHappened(event);
    But what happens if, just after you call Vector.size() for the last time, someone removes a listener from the list? Now, Vector.get() will return null (which is correct, because the state of the vector has changed since you last checked), and you will throw a NullPointerException when you try to call eventHappened(). This is an example of a check-then-act sequence -- you check to see if any more elements exist, and if so, you get the next element -- but in the presence of concurrent modification, the state could have changed since the check.
    I read that at IBM sites
    Thanks in advance for clearing my doubts...

  • Is ArrayList(Collection c) constructor  Thread-Safe?

    Hi,
    Say I have the following statement
    public List getList() {
            return new ArrayList(myList);
    }Assuming I also have other methods which use/modify myList, does this method above need to be synchronized?
    Looking into the ArrayList contructor, this eventually calls a static native method System.arraycopy, is this implicitly synchronized as it is native or do I need to take care of this myself?
    Thanks

    The constructor new ArrayList(List) is thread safe because no other thread can access the ArrayList until it because visable to another thread.
    The myList might not be thread safe. i.e. is possible you could be copying the myList while another thread is modifying it? If so then myList should be synchronized.
    Using Vector makes no difference as the list with an issue is myList. Even if myList was a Vector you would have same problem as more than one method is accessed so you would have race condition.
       public ArrayList(Collection c) throws NullPointerException {
            size = c.size();
            // Allow 10% room for growth
            elementData = new Object[
                    (int) Math.min((size * 110L) / 100, Integer.MAX_VALUE)];
            c.toArray(elementData);
        }Note: the c.size() can change between c.size() and c.toArray() being called or while c.toArray() is called. The race condition could mean the collection not being copies or an exception being thrown even if all the methods on the collection are synchronized.
    If you think Vector is so different.
        public Vector(Collection c) throws NullPointerException {
            elementCount = c.size();
            // 10% for growth
            elementData = new Object[
                    (int) Math.min((elementCount * 110L) / 100, Integer.MAX_VALUE)];
            c.toArray(elementData);
        }The only real solution is if myList can be modifed by another thread is to synchronize it and add the following.
    public List getList() {
       synchronized(myList) {
             return new ArrayList(myList);
    }

  • Component tree destroyed when it should not be

    I have a custom component which derives from UICommand, clicking on which pops up a new window ... i have a listener associated with this component ... within this listener I call the setAction(outcome) method on the associated UICommand component with an outcome string (whose navigation rule is defined in faces-config.xml) ... This works properly in that the new window opens with the correct JSP.
    However, in doing this, JSF destroys the component tree of my original page ... Hence when I perform some operation on the original page (after opening the new window), it constitutes a new tree instead of using the tree which was already created for this page ...
    How do I solve my problem? - I'd like the original component tree to not get destroyed as well as work with the new window.
    Thanks.

    Currently, JSF only saves the current tree (it does
    not save more than one tree). A new State Saving
    proposal is being developed which will
    address the problem you are having.
    -rogerWow, that's a pretty significant change. Can you give us any hints about other major differences currently under consideration for the next revision?
    Thanks,
    Jonathan

  • Repaint() is not thread-safe?

    I saw a description that says repaint() is thread-safe in an old swing tutorial, but not in the current tutorial and its javadoc. So can I assume repaint() is not thread-safe and I should call it from EDT? ... Or if they are thread-safe, why does Sun not document it?

    repaint() calls paint() on EDT... but it calculates dirty region on the current thread and does not get AWTTreeLock.I don't think so.
    repaint() is a java.awt.Component method and doesn't know about Swing's RepaintManager and dirty regions. There may be somthing similar at the AWT level that escaped me, but looking at the JDK1.6 source code, java.awt.Component.repaint() just repaints the whole component.
    Now repaint(long, int, int, int, int) has two versions.
    At the AWT level, it just posts a paint event for the specified region. No race condition, and no risk that he region be wrong, but possibility to invoke multiple paint(Graphics) that overlap, that is, to paint several times the same area - it may be an optimization problem, but it doesn't jeopardize the consistency of the drawing.
    At the Swing level, it does compute dirty regions. In Repaint manageer, the call to extendDirtyRegion(...) is protected within a synchronized block, but the code before that is not. From a quick look, that code is:
    1) walking up the component hierarchy to find the root, which may not be thread-safe, but a well-behaved application shouldn't change the hierarchy from outside the EDT.
    2) walking up a chain of "delegate" RepaintManager, which I knew nothing about... Apparently it's a sun's implementation specific construct, each JComponent can be assigne d a delegate RepaintManager. Again I would claim that such things should not happen outside of the EDT, but I haven't found documentation about this.
    Edited by: jduprez on Jul 20, 2009 2:37 PM
    so no, technically, I can't prove repaint(long, int,int,int,int) is thread-safe.
    But a well-behaved application that updates its widgets on the EDT shouldn't worry (that is, repaint(...) calls can still be invoked outside of the EDT).
    Edited by: jduprez on Jul 21, 2009 7:04 PM - typos

  • Thread safe servlets

    I have a question regarding the semantice of servlets. Consider you are calling a method
    public StringmodifyAddress(){......}in the service method of the servlet. Now considering that a servlet could be sericing multiple requests would this method be technically thread safe? If not what could we do to make it safe.
    cheers

    Ok let me rephrase and provide a little more details. Sorry I messed up the question the first time
    private String email;
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException
       User user = new User;
       String address =  user.modifyAddress(email);
    }Now in the class User
    public String modifyAddress(String email)
      //writes the email address to a database
    }Now I feel since user is a variable local to the service method it is thread safe, but a coworker feels that since email is a member variable it would not be thread safe. Please advise it seems that he might be correct.

  • Is Persistence context thread safe?  nop

    In my code, i have a servlet , 2 stateless session beans:
    in the servlet, i use jndi to find a stateless bean (A) and invoke a method methodA in A:
    (Stateless bean A):
    @EJB
    StatelessBeanB beanB;
    methodA(obj) {
    beanB.save(obj);
    (Stateless bean B, where container inject a persistence context):
    @PersistenceContext private EntityManager em;
    save(obj) {
    em.persist(obj);
    it is said entity manager is not thread safe, so it should not be an instance variable. But in the code above, the variable "em" is an instance variable of stateless bean B, Does it make sense to put it there using pc annotation? is it then thread safe when it is injected (manager) by container?
    since i think B is a stateless session bean, so each request will share the instance variable of B class which is not a thread safe way.
    So , could you please give me any guide on this problem? make me clear.
    any is appreciated. thank you
    and what if i change stateless bean B to
    (Stateless bean B, where container inject a persistence context):
    @PersistenceUnit private EntityManagerFactory emf;
    save(obj) {
    em = emf.creatEntityManager()
    //begin tran
    em.persist(obj);
    // commit tran
    //close em
    the problem is i have several stateless beans like B, if each one has a emf injected, is there any problem ?

    Hi Jacky,
    An EntityManager object is not thread-safe. However, that's not a problem when accessing an EntityManager from EJB bean instance state. The EJB container guarantees that no more than one thread has access to a particular bean instance at any given time. In the case of stateless session beans, the container uses as many distinct bean instances as there are concurrent requests.
    Storing an EntityManager object in servlet instance state would be a problem, since in the servlet programming model any number of concurrent threads share the same servlet instance.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Thread safe - again

    Hi guys,
    If I have 2 threads
    Thread one = new Thread();
    Thread two = new Thread();
    In each Thread (one, two) in run method, I new a class called MyClass
    public class myClass
    public int a;
    public int b;
    public int geta()
    return a;
    public int getb()
    return b;
    public void seta(int x)
    this.a = x;
    public void setb(int y)
    this.b = y;
    Is this thread safe. My result is not a thread safe. Does these 2 thread access the same memory block of myclass? I am really confused now.
    Thanks

    I agreed with the previous reply that the two myClasses shouldn't share the memory. But there are still many factors which may let them actually share the memory, such as you are actually implementing the two threads by putting the two myClasses into same variable (like static). Anyway, I think it is better for you to post how you create and store those classes in here. Then a clear reason and solution will come out.

  • Are queries thread-safe ? (continued)

    Hi
    In a previous thread on this topic, it was said that a query can be reused, and why it was good on performance. But a reusable object is not necessarily thread-safe.
    So I ask again. Are queries thread-safe ?
    What about Expressions ?
    Thanks
    JCG

    Yes, they're thread safe, both expressions and Queries. TopLink makes copies of whatever parts of the Query/Expression are needed to be changes in parallel.
    - Don

  • Are SocketFactory implementations thread-safe?

    Hi!
    I'm using a SSLSocketFactory-singleton (SSLSocketFactoryImpl it is I guess) for creating SSLSocket-instances in my application.
    I just wondered whether or not I need synchronization especially for using the createSocket(...)-methods in my multi-threaded application, since I can't look in the code due to restrictions. Another question is whether the answer applies to other SocketFactory implementations.
    Greetings

    georgemc wrote:
    JAVAnetic wrote:
    georgemc wrote:
    Why would you need SocketFactory to be thread-safe anyway?Because, in my multi-threaded application I want to use only one SocketFactory-instance to reduce the overhead of creating one per thread that needs Sockets. So this instance as a shared object used by many threads will need to be synchronized if it is not already thread-safe per se. But all you do with a SocketFactory is ask it for sockets. What issues do you think you'll face with multi-threaded requests for new instances of something? Just because you've got multi-threaded code, doesn't mean everything you use has to be synchronized.I know, but since I don't know what the factory-implementation actually does creating those instances I think it is always worth asking, if I have to synchronize even if it may be true that the design of (the) factory-implementation(s) is in fact thread-safe, which no one until now could tell me for sure.

  • Is Serialization a thread safe / concurrent access safe action?

    Hi,
    Is Serialization a thread safe / concurrent access safe operation? If not, how can one make sure a Serializable object won't be modified during the serialization process?
    Thanks!

    Jrm wrote:
    Is Serialization a thread safe / concurrent access safe operation?Serialization is not inherently thread-safe. It is up to you to make it thread-safe.
    If not, how can one make sure a Serializable object won't be modified during the serialization process?Control access to the objects you want to serialize so that no modifications occur during serialization.

  • Jpanel setBackground color thread safe?

    is this method thread safe?
    meaning do i have to use Invoke on the dispatch thread everytime or
    it doesn't really matter

    is this method thread safe?
    meaning do i have to use Invoke on the dispatch
    thread everytime or
    it doesn't really matterThat's not what thread safe means, but yes, you should be able to call it from any thread.

  • Are immutable objects thread safe

    I am having a debate with legosa as to if immutable objects are thread safe @
    http://forum.java.sun.com/thread.jsp?forum=37&thread=525250
    I would like the java gurus to put in their thoughts over here.

    I am having a debate with legosa as to if immutable
    objects are thread safe @
    http://forum.java.sun.com/thread.jsp?forum=37&thread=52
    250
    I would like the java gurus to put in their thoughts
    over here.There are some problems with the java memory model that can cause immutable objects to not be thread safe. This is discussed in the section Problem#1 in the following article from IBM:
    http://www-106.ibm.com/developerworks/library/j-jtp02244.html
    According to this article, some of the problems have been fixed in jdk1.4, while other fixes will have to wait until jdk1.5.

  • Thread programming -  variable might not have been initialized

    Hi there,
    Probably a fairly simple one here (quite new to java), i'm trying to do some thread programming but I get this error.
    ThreadController.java:42: variable dataGeneratorThread might not have been initialized
    dataGeneratorThread.activeCount();
    The bit I dont understand is that I run
    this line here
    for(int i=0; i < JuliaFrame.NO_OF_DATA_GENERATORS; i++){
    dataGenerators[i] = new DataGenerator(JuliaFrame.ImageWidth,JuliaFrame.ImageHeight,inputBuffer);
    dataGeneratorThread = new WorkerThread(dataGenerators,juliaCalc,displayBuffer);
    dataGeneratorThread.start();
    but when I do
    dataGeneratorThread.activeCount()
    is balks.
    I check that the thread is alive first but dont no how to tell the compiler this - obviously NO_OF_DATA_GENERATORS could be 0 in which case the compiler would have issues - I just wish it was more trusting ;)
    Here is some of the code
    runable class{
    new Thread( new ThreadController(inputBuffer,displayBuffer,juliaCalc) ).start();
    public class ThreadController implements Runnable {
    DataBuffer inputBuffer;
    DataBuffer displayBuffer;
    JuliaCalc juliaCalc;
    /** Creates a new instance of ThreadController */
    public ThreadController(DataBuffer inputBuffer,DataBuffer displayBuffer,JuliaCalc juliaCalc) {
    inputBuffer = inputBuffer;
    displayBuffer = displayBuffer;
    juliaCalc = juliaCalc;
    public void run()
    DataGenerator[] dataGenerators = new DataGenerator[JuliaFrame.NO_OF_DATA_GENERATORS];
         WorkerThread dataGeneratorThread;
         for(int i=0; i < JuliaFrame.NO_OF_DATA_GENERATORS; i++){
    dataGenerators[i] = new DataGenerator(JuliaFrame.ImageWidth,JuliaFrame.ImageHeight,inputBuffer);
    dataGeneratorThread = new WorkerThread(dataGenerators[i],juliaCalc,displayBuffer);
    dataGeneratorThread.start();
    dataGeneratorThread.activeCount();
    int nNanoSecsBeforeCheck = 50;
    while(true)
    if(dataGeneratorThread.isAlive()){
    if(dataGeneratorThread.activeCount() > inputBuffer.size())
    public class DataGenerator implements Runnable {
    int nImageWidth;
    int nImageHeight;
    DataBuffer inputBuffer;
    public DataGenerator(int ImageWidth, int ImageHeight,DataBuffer inputBuffer) {
    nImageWidth = ImageWidth;
    nImageHeight = ImageHeight;
    public void run()
    // Non terminating thread - created datapakets and place them in the input buffer
    // Get two radom number withoin a bound and find out bout default highest colou - 3rd value
    while(true)
    int nRandomXCord;
    int nRandomYCord;
    nRandomXCord = ((int)(Math.random() * nImageWidth));
    nRandomYCord = ((int)(Math.random() * nImageHeight));
    DataPacket dpDataPacket = new DataPacket(nRandomXCord, nRandomYCord, 233);
    inputBuffer.put(dpDataPacket);

    Sorry about that, didnt realise.
    Hi there,
    Probably a fairly simple one here (quite new to java), i'm trying to do some thread programming but I get this error.
    ThreadController.java:42: variable dataGeneratorThread might not have been initialized
    The bit I dont understand is that I run
    this line here
    this line here
    for(int i=0; i < JuliaFrame.NO_OF_DATA_GENERATORS; i++){
    dataGenerators = new DataGenerator(JuliaFrame.ImageWidth,JuliaFrame.ImageHeight,inputBuffer);
    dataGeneratorThread = new WorkerThread(dataGenerators,juliaCalc,displayBuffer);
    dataGeneratorThread.start();
    }but when I do
    dataGeneratorThread.activeCount() is balks.
    I check that the thread is alive first but dont no how to tell the compiler this - obviously NO_OF_DATA_GENERATORS could be 0 in which case the compiler would have issues - I just wish it was more trusting ;)
    Here is some of the code
    runable class{
    new Thread( new ThreadController(inputBuffer,displayBuffer,juliaCalc) ).start();
    public class ThreadController implements Runnable {
    DataBuffer inputBuffer;
    DataBuffer displayBuffer;
    JuliaCalc juliaCalc;
    /** Creates a new instance of ThreadController */
    public ThreadController(DataBuffer inputBuffer,DataBuffer displayBuffer,JuliaCalc juliaCalc) {
    inputBuffer = inputBuffer;
    displayBuffer = displayBuffer;
    juliaCalc = juliaCalc;
    public void run()
    DataGenerator[] dataGenerators = new DataGenerator[JuliaFrame.NO_OF_DATA_GENERATORS];
    WorkerThread dataGeneratorThread;
    for(int i=0; i < JuliaFrame.NO_OF_DATA_GENERATORS; i++){
    dataGenerators = new DataGenerator(JuliaFrame.ImageWidth,JuliaFrame.ImageHeight,inputBuffer);
    dataGeneratorThread = new WorkerThread(dataGenerators,juliaCalc,displayBuffer);
    dataGeneratorThread.start();
    dataGeneratorThread.activeCount();
    int nNanoSecsBeforeCheck = 50;
    while(true)
    if(dataGeneratorThread.isAlive()){
    if(dataGeneratorThread.activeCount() > inputBuffer.size())
    public class DataGenerator implements Runnable {
    int nImageWidth;
    int nImageHeight;
    DataBuffer inputBuffer;
    public DataGenerator(int ImageWidth, int ImageHeight,DataBuffer inputBuffer) {
    nImageWidth = ImageWidth;
    nImageHeight = ImageHeight;
    public void run()
    // Non terminating thread - created datapakets and place them in the input buffer
    // Get two radom number withoin a bound and find out bout default highest colou - 3rd value
    while(true)
    int nRandomXCord;
    int nRandomYCord;
    nRandomXCord = ((int)(Math.random() * nImageWidth));
    nRandomYCord = ((int)(Math.random() * nImageHeight));
    DataPacket dpDataPacket = new DataPacket(nRandomXCord, nRandomYCord, 233);
    inputBuffer.put(dpDataPacket);
    }

  • Reconstitute Component Tree

    How component tree was reconstituted?
    From jsp that have JSF tags or somehow else?
    I was read specification but nothing in detail about that.
    Is it define by specification or every JSF implementation can do it differently?
    For example page like this.
    Let assume that tree wasn't saved before.
    <HTML>
    <HEAD><title>Hello</title></HEAD>
    <%@taglib uri="http://java.sun.com/jsf/html"prefix="h"%>
    <%@taglib uri="http://java.sun.com/jsf/core"prefix="f"%>
    <body bgcolor="white">
    <h2>My name is Duke.What is yours?</h2>
    <jsp:useBean id="UserNameBean"
    class="helloDuke.UserNameBean"scope="session"/>
    <f:use_faces>
    <h:form id="helloForm"formName="helloForm">
    <h:graphic_image id="wave_img"url="/wave.med.gif"/>
    <h:input_text id="username"
    valueRef="UserNameBean.userName"/>
    <h:command_button id="submit"label="Submit"
    commandName="submit"/>
    </h:form>
    </f:use_faces>
    </HTML>

    Hi niksa_os,
    I think I might have misunderstood some of your question. I have put further comments below.
    "from the http session" - how when nothing about page
    isn't in session?On the first request (as you have probably noticed if you have built an app) none of the lifecycle is traversed except 'render response' in the RI.
    So, myFaces use JSP with JSF Tags to figure out what
    components
    to put in Tree(?)!Yes, exactly. But so does the RI, just at different times. myfaces uses the JSP with JSF tags at the beginning of the request during the 'reconstitute response tree'. The RI does not involve the JSP until the render response phase.
    How RI make Tree for the first time? Same or from the
    HTML request?During the first render response the JSP is rendered in the usual way. The JSF tags are invoked just like any other JSP custom tag would be invoked. During the tags processing (doStartTag, doEndTag etc) the JSF API is invoked to manage the tree. If a new componet must be created it is, if one is found to exist in the tree then its not created.
    After the tree is created and arranged as specified in the JSP then the renderers take over and make HTML from the components.
    Or is there any other way?
    I can't contrive third way, only from JSP/JSF and HTML
    request!
    What about XML output?
    How does it works?If I understand your question you would/could get XML output by implementing your own renderers.
    Hope this helps,
    -bd-

Maybe you are looking for

  • How to populate members in AD Directory Users group

    I have a Mountain Lion Server bound to Active Directory hosted on a Windows 2003 server.  After binding I can see all active directory users and groups in Server.app however some groups will not populate the group members, namely Domain Users, Domain

  • Pulling data from table to a flat file

    hi all, Good day to all, Is there any script which i can use for pulling data from tables to a flat file and then import that data to other DB's. Usage of db link is restricted. The db version is 10.2.0.4. thanks, baskar.l

  • How can I re-activate my account

    Hi can anyone help pls , my account as been disabled for security reasons , how do I reactivate it ? I have tried the change password thing numerous times !!                     Many thanks in advance darryl

  • Archive objets in mapped external server

    Hello All, My client does not have and want to install the SAP Content server for Archivelink, my suggestion is to map a external server on SAP server (like F: for exemple) that we could see in AL11 and place (also read)  the files there. Another ser

  • Blending options, fx, effects, copy, CS4

    Hi. In PS CS4 In my layers palette, I used to be able to have an effect (ex. drop shadow) on a layer & drag that effect onto another layer so the layers would have the exact same effect. In CS4 when I drag an effect, I lose that effect from that laye