I know the title looks like this post should go into the Servlets forum, but the servlet isn't my question.
When I was writing my servlet and asking questions about it I was advised to take out all variables. So I did. The only thing I have in my servlet are Object instances. Every time someone hits the doPost it will create an instance of the 3 objects I need so that I can populate my beans. This is all nice and clear to me now, but my question comes with the classes that I've written to do the processing.
What I'm trying to accomplish is that I need to populate a list of beans. I had this working but it wasn't in true MVC form so I have attempted to restructure it and now I'm getting an error. This is because my resultSet is returning null and when I do a .next() I get an sql exception error.
In my doPost I call a method called buildList(String) in my class ListOfBeans. buildList() returns a value of type List. My list i return will be an ArrayList of beans. I had not originally made my method static, but the compiler was yelling at me saying that "The method buildList(String) from the type ListOfBeans is not static". So I made it static and it compiles just fine.
Now, inside of buildList(String) I have to get a resultSet and add each row of the resultSet to my Bean and make that a row in my List. So I call an outside method called myRS(String) which is part of my class RS. I had to make myRS(String) static as well since it was yelling at me again.
So the question part...
I know that instances are references to an object. But each object is created by calling static methods of classes. Is this way of doing things thread safe? If I have two hits at the same time on my server will I be stepping on myself with the static classes or will it be ok since I'm using instances in my servlet?
Thanks
Bryce Martin
When I was writing my servlet and asking questions about it I was advised to take out all variables. So I did. The only thing I have in my servlet are Object instances. Every time someone hits the doPost it will create an instance of the 3 objects I need so that I can populate my beans. This is all nice and clear to me now, but my question comes with the classes that I've written to do the processing.
What I'm trying to accomplish is that I need to populate a list of beans. I had this working but it wasn't in true MVC form so I have attempted to restructure it and now I'm getting an error. This is because my resultSet is returning null and when I do a .next() I get an sql exception error.
In my doPost I call a method called buildList(String) in my class ListOfBeans. buildList() returns a value of type List. My list i return will be an ArrayList of beans. I had not originally made my method static, but the compiler was yelling at me saying that "The method buildList(String) from the type ListOfBeans is not static". So I made it static and it compiles just fine.
Now, inside of buildList(String) I have to get a resultSet and add each row of the resultSet to my Bean and make that a row in my List. So I call an outside method called myRS(String) which is part of my class RS. I had to make myRS(String) static as well since it was yelling at me again.
So the question part...
I know that instances are references to an object. But each object is created by calling static methods of classes. Is this way of doing things thread safe? If I have two hits at the same time on my server will I be stepping on myself with the static classes or will it be ok since I'm using instances in my servlet?
Thanks
Bryce Martin