Forums Register Login

synchronized Problem - variable return problem

+Pie Number of slices to send: Send
hi, i have 2 methods , which use synchronized, and both methods share a variable as following template code :



the problem here is when i set the list which in this case to size=2, but how come when i retrieve back the list using getParamList() and the size=0 ?

can anyone spot the problem , thanks for guidance

note :: i run this as utility class in my web application, which i start the method with simpleSQL() first then only generalQueryMethod()
+Pie Number of slices to send: Send
There's nothing wrong here, but you're obviously not showing the real code (the line

resultList = generalQueryMethod(String _query)

gives that away.) We can't find problems if we don't see the real code!

Nothing you've shown here involves multiple threads, so nothing requires these methods to be synchronized (of course, nothing requires "list" to be a member as opposed to a local, either, so again you're not showing us the whole picture.
+Pie Number of slices to send: Send
sorry for unclear, here is my real sample code, it might too long to show here, that's why i just give a scenario, and i take out the exception part









[ November 09, 2005: Message edited by: Nakata kokuyo ]
[ November 09, 2005: Message edited by: Nakata kokuyo ]
+Pie Number of slices to send: Send
Maybe you're confused about where the code is going? There are a lot of variables and methods with similar names here, and maybe you're looking at the wrong ones. I know it's hard for me to find my way around. For example, you show the method

public synchronized ResultSet getSqlResultSet(String _sql) throws NpException

but it isn't called anywhere in your example code; you don't show

List getSqlResultList(ResultSet rs)

which is called from getDefaultSalesmanInfo(); in fact, it's the only thing called after setSqlParam(), so it's the only thing that would have a chance to report the problem you're seeing. Take a good look at getSqlResultList() and see if that doesn't clear things up...
+Pie Number of slices to send: Send
getSqlResultList() code


+Pie Number of slices to send: Send
OK, so now, in the call tree starting from getDefaultSalesmanInfo(), you're never calling getSqlParam(). So how do you know that the member sqlList is of length 0?
+Pie Number of slices to send: Send
the getSqlParam() call from getSqlResultSet(), which is pass to another list

+Pie Number of slices to send: Send
Right, but that's [before you call setSqlParam(). Of course the list is still empty at that point; you haven't set it to anything yet.
+Pie Number of slices to send: Send
Ernest, you are right , i very disappointed with such stupid mistake,

anyway, when we use synchronized method, should we put all method as synchronized ?

for example, should i get rig on synchronized in getSqlResultSet() method? the reason i think on get rid it, is due to the getSqlResultSet() might share by other method..

say if getSqlResultSet() is a general method to execute query, it might call by other method as well , if i make it synchronized, would it affect other method which couldn't access it ?

lastly , thank you very much for your guidance and have a nice day
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1314 times.
Similar Threads
understanding J2SE 5.0 Enum
Synchronized method within a non-sync. method
Is accessing static class variables from non-static methods bad practice?
How to type cast the Object if im having class Name as string?
com.oreilly.servlet problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:00:52.