Prince Sewani

Ranch Hand
+ Follow
since Nov 24, 2010
Merit badge: grant badges
For More
Bhopal (M.P.-India)
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Prince Sewani

Just learnt that the proxies generated didn't have the additional transaction configs, explicitly added programmatic transaction bounds which turned the code to behave as expected.
Hi, any help on this will be much appreciated.
Hi,

I'm working on a java webservice(spring-jaxws), have a scenario where in two threads need to have their own transactional bounds un-related to each other to execute a set of statements in parallel, this application uses jdbc template and I've tried a bunch of things using Spring's @Transactional annotation. Have set the transactionSynchronization property to Never and also read here that if the @transactional is on a method in the same class as the initial thread it won't be activated/considered since spring's transaction management is proxy based. Not looking to make use of nested transactions, and propagation_required_new doesn't seem to work? Any suggestions? Been hitting my head against it for quite a while now. Can't post the code for confidentiality reasons but the description above is sufficient enough to explain my problem I believe(at least for those who've worked on Spring based transactiona management in a multi-threaded environment). Thanks in advance. Any help is much appreciated.
Hi Shiv,

I know that's a pretty high TAT, but I've so busy working on my skills lately that
didn't turn back, saw your post today. Well For preparing for SCJP 1.6, I read
Kathy & Sierra's SCJP preparation guide, that's an amazing book and is sufficient enough
to gear you up for the exam/interviews/ or if you're looking forward to get a kick start on
widing up your knowledge of Java.
All the best! Rock it!

shivdhwaj pandey wrote:how you have prepared for the exam ?
guide me i want to appear for ocpjp 6 in next few days.

11 years ago
Thanks.. I surely will.. I'll make sure that I do...

arulk pillai wrote:Congrats and keep up the good work

12 years ago
Thanks..

Paul Anilprem wrote:Congratulations!!!

12 years ago
Thanks..

Durgesh Vaishnav wrote:Congratulation

12 years ago
Hi All,

I cracked it today with 86%.

Finally, completed within 53 minutes,it comprised of 60 questions
and the duration was 150 minutes.

Thanks a tonne To Kathy and Bert for the book.

Although what I'm not happy with is that if you have a single question wrong belonging to
one objective, the exam report carries the whole objective mentioning that it wasn't clear to the
test taker, AS Pearson is taking care of the exams they should evolve the reporting mechanism
a bit. . Still No Offense!!

12 years ago
Hi Anayonkar,

Well, As I said earlier, I know all this, I was just looking for a practical example.
I got what you drawn out of the debit-credit example.

I found a working example for this in one of the Self Test Questions, here it is :

public class ThreadDemo {
synchronized void a() { actBusy(); }
static synchronized void b() { actBusy(); }
static void actBusy() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
}
public static void main(String[] args) {
final ThreadDemo x = new ThreadDemo();
final ThreadDemo y = new ThreadDemo();
Runnable runnable = new Runnable() {
public void run() {
int option = (int) (Math.random() * 4);
switch (option) {
case 0: x.a(); break;
case 1: x.b(); break;
case 2: y.a(); break;
case 3: y.b(); break;
}
}
};
Thread thread1 = new Thread(runnable);
Thread thread2 = new Thread(runnable);
thread1.start();
thread2.start();
}
}

About the scenario,when It is necessary to use both.. I'll get back to you on that..

Anayonkar Shivalkar wrote:Well, Prince, to understand this at code level, you can take the banking example from Sierra & Bates' SCJP book.

There, both methods - debit and credit (don't remember the exact names) are non-static and synchronized. You can make 1 method static and see that the code is not thread safe anymore.

e.g. debit is static and credit is non-static. Both are synchronized.
One thread is debiting 5 and other thread is crediting 3. Initial balance is 10.

1) credit thread acquires lock on object, and enters in credit method.
2) debit thread acquires lock on class, and enters in debit method.
3) credit thread reads the balance as 10.
4) debit thread reads the balance as 10.
5) credit thread credits the balance and writes to account. balance is now 13.
6) debit thread has already red the balance as 10, so it will debit 5 and write balance to account. balance is now 5.

In thread safe environment, no matter in which order these operations happen, final balance should always be 8 (i.e. 10 + 3 - 5 or 10 - 5 + 3).

Point here, is not about static or non-static method. It is on which object you are acquiring lock. If both methods are static or non-static, then it is guaranteed that those will try to acquire lock on same object ('this', or classname.class) and the methods will never execute concurrently (on same object of course). But static and non-static combination is like those methods are trying to acquire lock on two different objects, so one method will not wait for another. Static synchronized methods are used to maintain thread-safety of static members of a class.

I hope this helps. Btw, you are welcome to share if you get any example where it is necessary to use both static and non-static synchronized methods

Hi Anayonkar,

Thanks for the wonderful explanation, I understand all this, What I'm actually looking for is a practical working example that
justifies this scenario, I tried a couple of things but couldn't think of an exact design that will prove it.


Anayonkar Shivalkar wrote:Hi Prince,

To understand this statement, first, one should understand what is meaning of 'two methods block each other'.

This simply means that - on one object, two methods can never execute simultaneously. One method must wait till other method finishes.

How does this happen? Well, when two methods are object level (non-static) and synchronized, it is same has having a non-synchronized method with all lines of code inside synchronized(this) block.

So, when two threads try to call two synchronized method on same object, due to synchronization, only one thread will have object lock at a time and two threads cannot proceed concurrently.

But what if one method is static synchronized and another method is just synchronized (non-static)? At that time, even if two threads are executing two methods on same object, one thread (executing non-static method) acquires object level lock and proceed. Another thread (executing static method) acquires class level lock (i.e. synchronized(classname.class)) and proceeds (static methods are always class level even if called as obj.method()). And thus, a static synchronized method and a non-static synchronized method will not block each other, ever.

Hope this helps.

Hi all,

The line in the subject is on page 740 of SCJP- JAVA 6 -Exam study guide by Kathy Sierra &* Bert Bates,
Can some-one please provide an example that justifies it?

It will be of great help.

Oh yeah,Sorry I missed that one out..

Matthew Brown wrote:

Prince Sewani wrote:But the set contains i2 i.e. 46 right??


The set contains 46, which used to be the value of i2. But it isn't any more - you assigned i2 to a different object.

Hi Dennis,

But the set contains i2 i.e. 46 right??


Dennis Deems wrote:

Prince Sewani wrote:But Mathew,
I've a doubt,Set doesn't allows duplicates so the duplicate won't be added,it will be discarded rather,so when we remove i1,output is 1 that's fine and when we remove i2 as well,shouldn't the output be 0 in-spite of 1?



The set does not contain 47. So the command "set.remove(47)" has no effect. The set is unchanged and its size is still 1.

Hi Sanjeev,

There are a couple of libraries,depends on the way you want to use it..
For e.g., If you want to show your custom data,you can use Geo Server for the map's data-processing and deployement and Open Layer Javascript Library to interact
with the Geo Server from front-end/Client/Browser.

Just google about maps and browse all available and pick the one that you need.

sanjeev kumar mandal wrote:Hi All,

I need to create a dashboard that will contain the world map along with details of bussiness data for the particular location on the dashboard page.
If i move the cursor from one location to another then the bussiness data must be changed dynamically based on location.

Please suggest me if any third party jar we can use for the display of map and dynamically change the data based on the cursor position or on mouse hover.




Regards
Sanjeev Kumar

But Mathew,

I've a doubt,Set doesn't allows duplicates so the duplicate won't be added,it will be discarded rather,so when we remove i1,output is 1 that's fine and when we remove i2 as well,shouldn't the output be 0 in-spite of 1?

Matthew Brown wrote:What would you expect the output to be?

You add two numbers. You add a duplicate, but this is a Set, so it doesn't allow duplicates. You remove one of them. You then try to remove a different value, so that has no effect.