How Multi-User Java Applications Really Work












0















This question is rather broad I'm sure but I believe I don't fully understand how multi-user applications work and I would like some clarification on the subject or an idea of where to look for more info (not sure I know what to search for)



I understand the development aspect, but once you deploy the code to the server, how does it handle multiple users? For example, if I have a singleton class then that class will only ever be instantiated on the server once ... but the class will need to be used by multiple users simultaneously which means that the variables inside the class need to potentially be different for each user, how is this achieved behind the scenes?



Is it just the concept that each different user will access the class on a different thread? and if so, wouldn't that mean the whole application needed to be thread safe?










share|improve this question


















  • 2





    but the class will need to be used by multiple users simultaneously: yes, it most probably will. the variables inside the class need to potentially be different for each user: if they're local variables, then yes, each execution of a method uses variables separate from the other executions. If they're instance variables, then they're shared between all threads. wouldn't that mean the whole application needed to be thread safe: yes, a multi-threaded application needs to be thread-safe.

    – JB Nizet
    Nov 13 '18 at 19:53











  • Though it is common for applications (and frameworks, more generally) to carve out areas that are single-threaded. For instance, a framework for a web server may guarantee that any one request is only processed on one thread. Of course, any shared resources (including singletons) will still need to be thread safe

    – yshavit
    Nov 13 '18 at 20:03
















0















This question is rather broad I'm sure but I believe I don't fully understand how multi-user applications work and I would like some clarification on the subject or an idea of where to look for more info (not sure I know what to search for)



I understand the development aspect, but once you deploy the code to the server, how does it handle multiple users? For example, if I have a singleton class then that class will only ever be instantiated on the server once ... but the class will need to be used by multiple users simultaneously which means that the variables inside the class need to potentially be different for each user, how is this achieved behind the scenes?



Is it just the concept that each different user will access the class on a different thread? and if so, wouldn't that mean the whole application needed to be thread safe?










share|improve this question


















  • 2





    but the class will need to be used by multiple users simultaneously: yes, it most probably will. the variables inside the class need to potentially be different for each user: if they're local variables, then yes, each execution of a method uses variables separate from the other executions. If they're instance variables, then they're shared between all threads. wouldn't that mean the whole application needed to be thread safe: yes, a multi-threaded application needs to be thread-safe.

    – JB Nizet
    Nov 13 '18 at 19:53











  • Though it is common for applications (and frameworks, more generally) to carve out areas that are single-threaded. For instance, a framework for a web server may guarantee that any one request is only processed on one thread. Of course, any shared resources (including singletons) will still need to be thread safe

    – yshavit
    Nov 13 '18 at 20:03














0












0








0








This question is rather broad I'm sure but I believe I don't fully understand how multi-user applications work and I would like some clarification on the subject or an idea of where to look for more info (not sure I know what to search for)



I understand the development aspect, but once you deploy the code to the server, how does it handle multiple users? For example, if I have a singleton class then that class will only ever be instantiated on the server once ... but the class will need to be used by multiple users simultaneously which means that the variables inside the class need to potentially be different for each user, how is this achieved behind the scenes?



Is it just the concept that each different user will access the class on a different thread? and if so, wouldn't that mean the whole application needed to be thread safe?










share|improve this question














This question is rather broad I'm sure but I believe I don't fully understand how multi-user applications work and I would like some clarification on the subject or an idea of where to look for more info (not sure I know what to search for)



I understand the development aspect, but once you deploy the code to the server, how does it handle multiple users? For example, if I have a singleton class then that class will only ever be instantiated on the server once ... but the class will need to be used by multiple users simultaneously which means that the variables inside the class need to potentially be different for each user, how is this achieved behind the scenes?



Is it just the concept that each different user will access the class on a different thread? and if so, wouldn't that mean the whole application needed to be thread safe?







java multithreading






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 19:45









oznomaloznomal

71111




71111








  • 2





    but the class will need to be used by multiple users simultaneously: yes, it most probably will. the variables inside the class need to potentially be different for each user: if they're local variables, then yes, each execution of a method uses variables separate from the other executions. If they're instance variables, then they're shared between all threads. wouldn't that mean the whole application needed to be thread safe: yes, a multi-threaded application needs to be thread-safe.

    – JB Nizet
    Nov 13 '18 at 19:53











  • Though it is common for applications (and frameworks, more generally) to carve out areas that are single-threaded. For instance, a framework for a web server may guarantee that any one request is only processed on one thread. Of course, any shared resources (including singletons) will still need to be thread safe

    – yshavit
    Nov 13 '18 at 20:03














  • 2





    but the class will need to be used by multiple users simultaneously: yes, it most probably will. the variables inside the class need to potentially be different for each user: if they're local variables, then yes, each execution of a method uses variables separate from the other executions. If they're instance variables, then they're shared between all threads. wouldn't that mean the whole application needed to be thread safe: yes, a multi-threaded application needs to be thread-safe.

    – JB Nizet
    Nov 13 '18 at 19:53











  • Though it is common for applications (and frameworks, more generally) to carve out areas that are single-threaded. For instance, a framework for a web server may guarantee that any one request is only processed on one thread. Of course, any shared resources (including singletons) will still need to be thread safe

    – yshavit
    Nov 13 '18 at 20:03








2




2





but the class will need to be used by multiple users simultaneously: yes, it most probably will. the variables inside the class need to potentially be different for each user: if they're local variables, then yes, each execution of a method uses variables separate from the other executions. If they're instance variables, then they're shared between all threads. wouldn't that mean the whole application needed to be thread safe: yes, a multi-threaded application needs to be thread-safe.

– JB Nizet
Nov 13 '18 at 19:53





but the class will need to be used by multiple users simultaneously: yes, it most probably will. the variables inside the class need to potentially be different for each user: if they're local variables, then yes, each execution of a method uses variables separate from the other executions. If they're instance variables, then they're shared between all threads. wouldn't that mean the whole application needed to be thread safe: yes, a multi-threaded application needs to be thread-safe.

– JB Nizet
Nov 13 '18 at 19:53













Though it is common for applications (and frameworks, more generally) to carve out areas that are single-threaded. For instance, a framework for a web server may guarantee that any one request is only processed on one thread. Of course, any shared resources (including singletons) will still need to be thread safe

– yshavit
Nov 13 '18 at 20:03





Though it is common for applications (and frameworks, more generally) to carve out areas that are single-threaded. For instance, a framework for a web server may guarantee that any one request is only processed on one thread. Of course, any shared resources (including singletons) will still need to be thread safe

– yshavit
Nov 13 '18 at 20:03












1 Answer
1






active

oldest

votes


















1














Let me explain this straight and will start from this point



once you deploy the code to the server, how does it handle multiple users?



----> Yes every web application or enterprise application should be deployed in server, web application on web server like tomcat enterprise applications on WebSphere. Every server will have servlet container with multiple number of threads (by default 200 in tomcat) each input request will be handled by individual thread (so multiple request can execute concurrently)



if I have a singleton class then that class will only ever be instantiated on the server once



---> yes singleton class will have only one instance per server, so multiple threads can access same object concurrently and which may cause data inconsistency, which is developer responsibility to take care of this responsibilities. The main problem with singleton class will be class (instance or static) level variables with setter methods because two threads can access same object concurrently and change the values, In the real time scenario singleton design pattern is used for Connection Pool object



Note Local variables are best in multithreading because every thread has its own stack, and they cannot be access by any other threads.



but the class will need to be used by multiple users simultaneously which means that the variables inside the class need to potentially be different for each user



---> To save request properties into object Models or POJO will comes into picture, these are prototype for every request new object will be created.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288420%2fhow-multi-user-java-applications-really-work%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Let me explain this straight and will start from this point



    once you deploy the code to the server, how does it handle multiple users?



    ----> Yes every web application or enterprise application should be deployed in server, web application on web server like tomcat enterprise applications on WebSphere. Every server will have servlet container with multiple number of threads (by default 200 in tomcat) each input request will be handled by individual thread (so multiple request can execute concurrently)



    if I have a singleton class then that class will only ever be instantiated on the server once



    ---> yes singleton class will have only one instance per server, so multiple threads can access same object concurrently and which may cause data inconsistency, which is developer responsibility to take care of this responsibilities. The main problem with singleton class will be class (instance or static) level variables with setter methods because two threads can access same object concurrently and change the values, In the real time scenario singleton design pattern is used for Connection Pool object



    Note Local variables are best in multithreading because every thread has its own stack, and they cannot be access by any other threads.



    but the class will need to be used by multiple users simultaneously which means that the variables inside the class need to potentially be different for each user



    ---> To save request properties into object Models or POJO will comes into picture, these are prototype for every request new object will be created.






    share|improve this answer




























      1














      Let me explain this straight and will start from this point



      once you deploy the code to the server, how does it handle multiple users?



      ----> Yes every web application or enterprise application should be deployed in server, web application on web server like tomcat enterprise applications on WebSphere. Every server will have servlet container with multiple number of threads (by default 200 in tomcat) each input request will be handled by individual thread (so multiple request can execute concurrently)



      if I have a singleton class then that class will only ever be instantiated on the server once



      ---> yes singleton class will have only one instance per server, so multiple threads can access same object concurrently and which may cause data inconsistency, which is developer responsibility to take care of this responsibilities. The main problem with singleton class will be class (instance or static) level variables with setter methods because two threads can access same object concurrently and change the values, In the real time scenario singleton design pattern is used for Connection Pool object



      Note Local variables are best in multithreading because every thread has its own stack, and they cannot be access by any other threads.



      but the class will need to be used by multiple users simultaneously which means that the variables inside the class need to potentially be different for each user



      ---> To save request properties into object Models or POJO will comes into picture, these are prototype for every request new object will be created.






      share|improve this answer


























        1












        1








        1







        Let me explain this straight and will start from this point



        once you deploy the code to the server, how does it handle multiple users?



        ----> Yes every web application or enterprise application should be deployed in server, web application on web server like tomcat enterprise applications on WebSphere. Every server will have servlet container with multiple number of threads (by default 200 in tomcat) each input request will be handled by individual thread (so multiple request can execute concurrently)



        if I have a singleton class then that class will only ever be instantiated on the server once



        ---> yes singleton class will have only one instance per server, so multiple threads can access same object concurrently and which may cause data inconsistency, which is developer responsibility to take care of this responsibilities. The main problem with singleton class will be class (instance or static) level variables with setter methods because two threads can access same object concurrently and change the values, In the real time scenario singleton design pattern is used for Connection Pool object



        Note Local variables are best in multithreading because every thread has its own stack, and they cannot be access by any other threads.



        but the class will need to be used by multiple users simultaneously which means that the variables inside the class need to potentially be different for each user



        ---> To save request properties into object Models or POJO will comes into picture, these are prototype for every request new object will be created.






        share|improve this answer













        Let me explain this straight and will start from this point



        once you deploy the code to the server, how does it handle multiple users?



        ----> Yes every web application or enterprise application should be deployed in server, web application on web server like tomcat enterprise applications on WebSphere. Every server will have servlet container with multiple number of threads (by default 200 in tomcat) each input request will be handled by individual thread (so multiple request can execute concurrently)



        if I have a singleton class then that class will only ever be instantiated on the server once



        ---> yes singleton class will have only one instance per server, so multiple threads can access same object concurrently and which may cause data inconsistency, which is developer responsibility to take care of this responsibilities. The main problem with singleton class will be class (instance or static) level variables with setter methods because two threads can access same object concurrently and change the values, In the real time scenario singleton design pattern is used for Connection Pool object



        Note Local variables are best in multithreading because every thread has its own stack, and they cannot be access by any other threads.



        but the class will need to be used by multiple users simultaneously which means that the variables inside the class need to potentially be different for each user



        ---> To save request properties into object Models or POJO will comes into picture, these are prototype for every request new object will be created.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 20:07









        DeadpoolDeadpool

        5,9132528




        5,9132528






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288420%2fhow-multi-user-java-applications-really-work%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            Bicuculline

            さくらももこ