0

Whether this program runs on single thread or multi thread??

Servlet

public class PagesNavigation extends HttpServlet {

    private static final long serialVersionUID = 1L;
    public UserData user = null;

    public void init(ServletConfig config) throws ServletException {
        super.init(config);

        try {
            user = new UserData();  //I will use this object to access all functions.

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

class: UserData

 public class UserData {

    AvailableProducts availableProducts = new AvailableProducts();
    UserSelectedProduct userSelectedProduct = new UserSelectedProduct();
    ProductsCart productsCart = new ProductsCart();
    CartView cartView = new CartView();
    ProductsForCheckout productsForCheckout = new ProductsForCheckout();
}

Thanks for any help.

Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
Anjanaa
  • 468
  • 1
  • 4
  • 13
  • 1
    You should have a look at [how do servlets work](http://stackoverflow.com/questions/3106452/how-do-servlets-work-instantiation-sessions-shared-variables-and-multithreadi). – Mick Mnemonic Sep 04 '16 at 16:22

2 Answers2

1

Just to clarify - servlets are singletons, and they are definitely run by multiple threads.

Also, AvailableProducts could possibly also be a singleton and shared among all users - unless you custom tailor the products for a given user.

Rodney P. Barbati
  • 1,883
  • 24
  • 18
0

If you're doing Java Enterprise Edition programming (which HttpServlet normally is), then it's all multi-threaded, with a very few specific exceptions. Your UserData object will almost certainly need to be thread safe.

markspace
  • 10,621
  • 3
  • 25
  • 39