Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!

Abhishk Singh

Ranch Hand
+ Follow
since Aug 19, 2010
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Abhishk Singh

Thanks for clarifying Salvin.

Campbell Ritchie wrote:Come to thin of it: would a StringBuffer lose its th‍read‑safety as a static field?

Right. Even if its a StringBuffer, because its shared between different threads. If there are 4 statements modifying the stringBuffer object with first statement resetting it inside the method concatenateStrings and one thread loses control after executing 2nd statement and another thread starts at 1st statement and resets the buffer, we lost the modification done by thread one.

Mohammed Sardar. wrote:Abhishk, If we don't bother to use append method in return, we we should not try and see with StringBuffer which is fail-safe too ?

Only a suggestion.Please add your thoughts to it if there is any impact.

HI Mohammed, here is my understanding on the use of StringBuffer:
1. Thread safety costs some performance, so we should not use it until we really need it.
2. Rather than using "+" for concatenation of strings, StringBuffer and StringBuilder are more optimized for such operations. And among them, StringBuilder should be used until thread safety is required. So this program can be modified to use a StringBuilder which can be initialized locally in the method and can return the result after concatenation.
3. Thread safety wise, StringBuilder or StringBuffer does not matter in this method if initialized locally inside the "concatenateStrings" . But it would matter if it becomes a Static variable of the class in which static contatenateStrings method is defined.

Campbell Ritchie wrote:That is mistaken, I am afraid. Strings aren't primitives. The name of the method looks misleading, too.

My bad. Thanks for correcting. I wrote the method with int inputs earlier and performed add opteration on them. But to make the method look more like what my actual requirement is, changed inputs to string just before posting the question. It should have looked like below:

is below method prone to run into synchronization errors when multiple threads are executing it:

My understanding is that since str1 and str2 are primitive and being passed from the caller, and every caller's method stack is separate, there should not be any issue.
The synchronization issues will come when threads have access to same instance variables (or in case of static methods, same static variables). It could be an issue if the caller threads were passing object references to same objects. Also, there should not be any issues if we are using only method local variables (be it primitive or non-primitive).

So suppose there are 2 threads calling this method:
Thread 1: str1="Good" , str2="Morning"
Thread2: str1="Hi", str2="There"

then as per my understanding above code will never run into issue of returning "Good There" or "Hi Morning".
Could you please validate/correct my understanding on this.

Check if the machine A is reachable from machine B. As Tapas has suggested, run the telnet command on machine B command prompt.
If it is connected properly, then may be database is not registered with the listener. Next time you get error, try restarting the db server on machine A and test your code again.

Sanurag Dharme wrote:
but then its giving me following error when I am trying to access the database from sql developer

Are you getting this error when running the query on SQL developer installed on machine B trying to access database server installed on machine A?
This link describes probable causes and potential solutions:

So if my database is installed on machine A and I want to access database form machine B. Then I have to provide machine A's IP address right??


do I need to install Oracle client on machine B

No. You need it only in case you want to run queries using the oracle client from machine B. But you will need database driver classes/jar file containing driver classes on machine B in your classpath.
Not sure about public or private IP.
When the machines are connected over the LAN, you can configure the the ip in LAN properties. The IP configured there should work.
IP configured in properties of machine B, should be used by the program running on machine A.

localhost points to the servers configured on the local machine. To hit server on machine B from machine A, you should be using that machine's IP instead of localhost. The URL would be like . To configure alias name for IP, you can modify hosts file in your system to point to IP eg. : <IP> dbServerURL on Windows and then use this string:
I could do it using WID and WPS and got it verified.
JTA seems as a good alternative. Will verify it too. Thanks for the input.
3 years ago
I need to call a db procedure 3 times. All 3 calls will be in 3 different db sessions. The requirement is such that if any of the 3 calls fail, all three transactions should roll back. The respective commits should happen only when all 3 procedures have executed successfully.

Already tried solutions:

Initiate 3 different connections inside a method. Call the procedure on those connections, and when one of them fails, call rollback on all connections. When the execution of 2nd call failed, I called rollback 1st connection. This resulted in a SocketException. I do not have the stacktrace available.

Using IBM WID and WPS: Encapsulated the db service calls in a single WPS server transaction and made 3 calls to database procedure. This resulted in partial commit, that is, the first call resulted in an insert inside database and did not rollback after the failure of 2nd call.
3 years ago
Thank you for valuable suggestions.

If you want a "universal" UI for all mobile devices using HTML without considering alternative rendering systems, the key is in using proper layout components and appropriate CSS skins.

What I make from above statement is that I'll have to chose JSF view components (panelgrid,dropdowns,buttons etc) and provide proper styling to them using CSS, avoiding pixel coordinates. Am I right?
4 years ago
Is it feasible to create a single UI in JSF which renders fine on different type of screens namely desktop and mobile device screens?
4 years ago
Thanks for the inputs.
I agree with the points both of you make. The current situation at my hand is such that I have a class which has a large number of lines of code. The code is tested and running fine. In fact it is old code and has been running properly for years. I am looking for measures required to perform performance tuning of the code.
Dividing the large class code to small classes will involve a lot of impact analysis and testing. So need your inputs on the line that whether this exercise of breaking the code to small classes is worth the effort.
Also, is it more memory intensive to have a large class instead of having the code divided in small classes, as I have already mentioned as per the requirement all classes will be initialized simultaneously.
4 years ago