Announcement Announcement Module
Collapse
No announcement yet.
ApplicationContext and threading. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ApplicationContext and threading.

    I have got a basic question related to applicationContext and threading, I have a standalone java application that spawns 20 threads and each thread performs identical set of operation, based upon record they fetch from database the question that I have here is if the code that execute in thread load the application context like below.

    ApplicationContext context = new FileSystemXmlApplicationContext("somebath/x.xml");

    Does it mean that there are 20 application context and each application context will create its own copy of singleton object (as defined in the spring config file). Or is there a single global application context across all the threads and objects are being shared across the board.

    Thanks
    Arjun

  • #2
    Re: ApplicationContext and threading.

    Originally posted by arrow_us_dc
    I have got a basic question related to applicationContext and threading, I have a standalone java application that spawns 20 threads and each thread performs identical set of operation, based upon record they fetch from database the question that I have here is if the code that execute in thread load the application context like below.

    ApplicationContext context = new FileSystemXmlApplicationContext("somebath/x.xml");

    Does it mean that there are 20 application context and each application context will create its own copy of singleton object (as defined in the spring config file). Or is there a single global application context across all the threads and objects are being shared across the board.

    Thanks
    Arjun
    I don`t know how the FileSYstemXmlApplicationCOntext works, but why don`t you inject the dependencies in the threads of your system. They don`t need to know about the appcontext.

    Comment


    • #3
      You are creating each time a new File appContext so each thread contains a different appContext. Is a lot easier to do what alarmnummer suggested or simply create a manager that loads the appContext once and then spawns the threads.

      Comment

      Working...
      X