Horia Constantin

Greenhorn
+ Follow
since Sep 23, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Horia Constantin

Happy New Year Guys,

I'm having some problems with spring and I was hoping you could enlighten me.
I've been searching all over the internet and I haven't found a solution to this, but I'm kind of new and maybe I'm looking for the wrong things.

My problem: I have a Spring portlet (org.springframework.web.portlet.DispatcherPortlet) and it has 2 views. The first displays some personal data and the other allows the changing of personal data. The problem is: I go into the view to change personal data on the portlet, after that I navigate on some other page and I come back to the portlet I find the change personal data view. I know this is the proper behaviour of the portlet (as it remembers it's last state); but what I really need is to display the personal data when I return to the portlet (practically to reset the state of the portlet).

How could I do this? are there any workarounds? Even the smallest suggestion could help.

Cheers,
Horia
15 years ago
Well, I can say from start that that code will never compile because you cannot have 2 returns like that (one after another). It will not compile (and probably say statement unreachable).

The question that arises... Didn't you check the error given by the compiler at compile time? That should have been pretty obvious.

Next time pay more attention to what the compiler has to say (questions like these are to be expected at the exam).

Cheers,
Horia
Hey guys,

After taking my SCJP exam, thanks to the advices on JavaRanch I started working with IBM Websphere. Needless to say I'm a complete noob.

What I wanted to do: from a portal I created (more precisely, from a portlet in the portal) I want to do a redirect to another portlet. So I created on the portal a page with unique identifier: ing.internet.LifeInsurance.Contract. And after that I refered it from a jsp in another portlet like this:



However, I get the following error when I click the link on the jsp page:

[11/30/09 10:44:11:953 EET] 00000047 UrlGeneration W com.ibm.wps.engine.tags.UrlGenerationTag setContentNode EJPEJ0099W: Could not deserialize the content node ID: ing.internet.LifeInsurance.Contract

What am I doing wrong? Maybe you could direct me to some relevant docs?

Cheers,
Horia



15 years ago

Siva Masilamani wrote:No it will not work that way


Why not?
If i comment out the x in the interface the compiler then realizes that x is being called in a static context. Why doesn't the compiler know this at first?
Hi,

This code is annoying.
The way I see it, x is called from a static context, so there should be no problem, because the only static x in the code is the one from the interface (=1).
But the compiler says the reference is ambiguous??? Why is that?

Thanks,
Horia
Yes, I understand that now. Please see my revised answer in the posts above (I have edited them).

Dany Mariana wrote:Sorry but I think I don't understand. In the first example, the one from the book, the look is for object not for class. It is a method syncronized and the syncronized object is this no a static object of the class.

Horia Constantin wrote:Give me some time to make some tests as I seem to have been misled by your example and I think the explanation is different from the ones I gave you

The new code you wrote is quite different from what you had in the beginning.
In the first version (Dudes) you had a static long flag. When entering the synchronized method, the thread got the monitor lock for the class (aka because you have static the thread gets the lock for the class). And both threads in the example use the same class lock, that's why one of the threads must wait for the other one to finish.
Am I clear until now?

On the other hand, in your second example (TestThreadSyn) you designed a class with threads that get objects' lock (they are synchronized on the actual Threads objects, which are different; therefore the output is unpredictable).
Was I explicit enough?

Cheers,
Horia

I'm sorry for misinforming you in the beginning (apparently I was also misinformed). But it's clear to me now.
According to my revised explanation from above, this time you are using your threads with different objects (ch and new C()).
new Thread(ch).start(); gets the object lock for the ch object
new Thread(new C()).start(); gets the object lock for a new C object.
Soooo, different locks, unpredictable output.
If you were to write:
the output would be as you expected: yo dude yo dude yo dude yo dude

Hope I'm clear this time.

Cheers,
Horia

P.S.: Thanks for the opportunity you gave me to study the threads deeper.

The new code you wrote is quite different from what you had in the beginning.
In the first version (Dudes) you had a static long flag. When entering the synchronized method, the thread got the monitor lock for the class (aka because you have static the thread gets the lock for the class). And both threads in the example use the same class lock, that's why one of the threads must wait for the other one to finish.
Am I clear until now?

On the other hand, in your second example (TestThreadSyn) you designed a class with threads that get objects' lock (they are synchronized on the actual Threads objects, which are different; therefore the output is unpredictable).
Was I explicit enough?


Cheers,
Horia
Hi,
Yesterday I was checking out generics and found this: http://java.sun.com/docs/books/tutorial/java/generics/gentypes.html (scrool down to Type Parameter Naming Conventions).

The most commonly used type parameter names are:
* E - Element (used extensively by the Java Collections Framework)
* K - Key
* N - Number
* T - Type
* V - Value
* S,U,V etc. - 2nd, 3rd, 4th types

Cheers,
Horia
hi,
Please explain the behaviour of the following:Out 1,0
I can understand where 0 comes from, but the 1 blows my mind. Why on earth would anyone write that? I guess the exam tests where I get this or not so please explain in detail.

Cheers,
Horia

Dany Mariana wrote:I understand that synchronized means that 2 threads can't access in the same time a method. This means they can go out a method before completed and reenter later to complete. Am I wrong?



LE: I have revised the initial explanation because it contained wrong informations
If you have a synchronized method and one thread enters it, no other threads can enter it (or alter the objects/classes that it involves) until the thread exists the method.(because the thread owns the lock for the object; no other threads will be able to enter any of the synchronized code that is referring to this object)

In your case, for synchronized void chat(long id) the first thread that enters the method finds the flag=0 (keep in mind that once it enters the method it will run until the for loop ends) and then the if is true so flag gets set with the id value so the if (flag==id) will return true every time (also you should keep in mind that both threads use the same object for invoking the synchronized method chat (d = new Dudes();) and d.chat) , therefore the output should be:

yo yo dude dude (this being the only possible alternative).

Cheers,
Horia
@Vivek
I don't understand you explanation...
compiles fine

@Andre: I agree with you, but why do we get this behaviour
@Vivek:

Method with varargs is called only when no other method signature matches the invocation.

in your case the signatures are same.
Good question though i also didnt know about this behaviour. ty

You're stating the obvious.. why aren't the signatures ok?

@Ankit: the code is not ok... compilation fails
I just read the thread...

WOW! Great way to reply Ankit. The answer was really diplomatic and constructive without being aggressive.

You're a model of a moderator

treaz

suman mitragupta wrote:I can't see any wrong answer . Can you please explain ?



In fact, it turned up to be a problem with the html page and my browser interpreting the <generics> as tags.

But it seems to be ok right now, so do not take into consideration my previous comment.

Cheers,
treaz
Hi,

If an administrator could look into this it would be great...
Regarding the SCJP Mock Tests links given on http://faq.javaranch.com/java/ScjpMockTests.

The third link http://www.javacertifications.net/javacert/scjp1.6Mock.jsp is full of mistakes (in 35 questions i found 4 important mistakes (wrong answers)).
Maybe someone could investigate and eventually remove that link as it does more bad than good.

For example: Q4; Q34; Q20; Q28.

After this I stopped trying to solve the questions on the site.

Cheers,
Horia