Adam Michalik

Ranch Hand
+ Follow
since Feb 18, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
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 Adam Michalik

Thanks, Tim. I supposed that it might be a security risk to allow for such listing. I'll have to duplicate this servlet configuration in web.xml and in the place where I need it, then.
10 years ago
Is there a way to access servlet configuration data of a given servlet (not the one currently handling the request)? I have an application with a JSF (Faces) servlet and servlet MyServlet. I want to programmatically access (read) access MyServlet's url-pattern as it was configured in web.xml from a request that is handled by the Faces Servlet. Is it possible at all?
10 years ago
Have you searched first? I found at least one solution for Java 5 on the "Java in General" forum.
There's also a great article here, on JavaRanch.
11 years ago
And what would be the point of such synchronization? If you want to synchronize the threads (eg. to avoid race condition, protect some resources etc.), you should do it externally (ie. in the MyThread class for instance), not in the utility class. Utility class is a kind of a library - you wouldn't want libraries to determine how your application is synchronized, would you? Now, if the only point is to have the log messages be written nicely in order... that's a bit tougher. I'd propose to output the thread ID and/or some other ID for each thread. Some logging frameworks like log4j can do it for you. Then you can brows the logs and trace which call was in which thread. Synchronizing just to get the log entries in order could result in a big performance penalty.
11 years ago
Well, have you tried it? Try to create an array with statically defined size. Then, try to declare it's size as an int variable and use it as the array's size. What happens?
11 years ago
It depends First of all, i depends whether you have or want to have more than one constructor. If not, then 2) = 3). By "outside of constructor" do you mean in a method or at declaration time? If in a method, then it depends whether you want to initialize your values only once, at construction time (if so, 1) = 2)), or more than once (re-initialize them at some later time). If at declaration time, then 1) = 3). Apart from that, it's a matter of code maintainability and flexibility - sometimes it's better to have eg. setters for initialization, sometimes a method that initializes all the fields at once (eg. init()) and can be called after construction and sometimes you may want to initialize the fields in a constructor only and never change the value again. And sometimes it's just easier to read if you do this one way or another. So, really, it depends
11 years ago
I don't really thing that's a "Java in general" question, nor do I know much about SSO and Liferay, but the stacktrace says:


Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target


Do you have the whole certification chain properly installed, ie. your ceritficate and the certificates that sign your certificate?
11 years ago

s begri wrote:If I want to access the non static method how could I access ?


Well, you simply need an instance of that class to call a non-static (instance) method.
11 years ago
Thread.sleep(long) is native because it is mapped directly onto the underlying operating system's thread management (ie. on Windows it behaves differently than on Linux or Solaris or any other system). Thread.sleep(long, int) is not native, because id does some internal logic in Java and then calls Thread.sleep(long). See the source code for details.
And what do the Javadocs say?
12 years ago
Plus, with DOTALL (java.util.regex.Pattern):

Javadoc wrote:the expression '.' (dot) matches any character, including a line terminator. By default this expression does not match line terminators.


Which means that if your regexp is scattered in multiple lines, you can still find it (if you use the dot character properly).
12 years ago
That would be technically impossible. If you create an array as int[], the ints are stored directly in the array. If you create it as Object[] or Integer[], the references are stored in the array and the object elsewhere (on the heap). So suppose you had:

Now, the compiler, when it compiles class B does not know that the objects array is full of ints and threats it as if it was full of references. So when you try to access objects[1], it generates instructions to access an object via a reference. Auto(un)boxing happens at compile time, so there is no possibility to make an object from that int during runtime.
12 years ago
Then I'm sure it's not the map itself that "eats" the memory, but the objects stored in it. I'd approximately count like this (in bytes):
4 * map.size() + 2 * sum of all key (String) lengths + sum of all values. Of course the most problematic question now is "What is the size of your value object?". If it keeps references to many other objects, then the memory consumption can be high.
12 years ago

Campbell Ritchie wrote:if you try to call the method from "A" then your "C" object NO-LONGER-IS-An "A".
And I won't tell you how you can cheat with a classcast.


I believe you meant NO-LONGER-IS-An "B"? Because it's B one would be skipping. And I hope that the strike means "Don't even try to read it" - class casting won't help as the inherited methods are invoked virtually, so anyway the method closest in the class hierarchy would be selected.
12 years ago