Dave Wingate

Ranch Hand
+ Follow
since Mar 26, 2002
Merit badge: grant badges
For More
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 Dave Wingate

Leandro Coutinho wrote:But the run() method in the Thread class that should be executed, right?
He called the super constructor passing an implementation of Runnable as parameter, that just prints "Doing some useful, long-running unit of work."
So I don't understand how the run() method in the LoggingThread class is called. Please help me.

Calling the start() method on the Thread class starts a new background thread that executes the Thread's run() method:

So what does the Thread's run() method do? The key insight is that, because the Thread was constructed with a Runnable argument, the Thread's run method will call the run() method of the Runnable:
14 years ago

Leandro Coutinho wrote:
I would like to know:
- What does "more specialized version" mean? Does it mean override a method?

Considering the Thread/Runnable combination, there are two important and separate concerns in play:

- Define WHAT unit of work is to be executed. This concern gets defined in the Runnable.

- Define HOW to execute a unit of work in a separate thread. This concern gets defined in the Thread. There are potentially many different nuances to this "how" concern. For example, we might want to write a log message whenever a new Thread is created or executed. In such cases, you could define a more specialized version of Thread.

Here's a toy example, demonstrating the distinction described above:

14 years ago
Doh! I failed to notice those methods. Many thanks for your patience.
14 years ago
Thanks, Rob. I took a look at the API for TreeNode and DefaultMutableTreeNode. I see how I could use those classes to build a tree data structure. What I wasn't able to find were any utility classes used to search through a tree of TreeNodes. Anybody know of any global tree search implementations in any of the Java packages or ancillary frameworks?
14 years ago
Howdy Ranchers,

I was wondering if any one can point me to a package or framework for working with objects that are linked in a tree structure. I know all about TreeSet and TreeMap, but those are data structures that are backed by trees. What I'm looking for are interfaces and utility classes that explicitly expose and utilize the tree-like references among a group of objects. Something along the lines of ...

TreeNode node = ...;
SomeUtilityClass.search(node, "search query");

Is there such a package? Or does everyone end up writing their own little BFS and DFS tree search algorithms?
14 years ago
I did eventually figure this out. And the problem had nothing to do with SSL. For anyone else who needs to solve a similar problem, the root cause for me was an uber-old application server that didn't properly decode UTF-8.
Hi Ranchers,
I'm in a bit of a pickle and am hoping someone will set me in the right direction. The problem I'm trying to solve is in the context of a web application. The user types a character string in the browser, then we use AJAX to pass the user's string to the server, which persists the string to the DB. All pretty normal stuff. The problem arises when the user's string contains international symbols.

if the user types in "bénévoles" we call encodeURIComponent(..) to get "b%C3%A9n%C3%A9voles" ... the value that is stuffed into the AJAX request to the server. The problem is that sometimes the value received by the server is not "bénévoles" but "bénévoles" .... strange stuff! I say that the server sometimes gets that "bénévoles" value because I've only been able to reproduce the behavior on a deployed instance of our product, not on my local development machine. The most obvious delta I see between my development box (no problem) and our deployed product (user text garbled) is the the former isn't using SSL, but the latter does.

I'm thinking I'll try to introduce SSL to my development box in an effort to reproduce the problem ... but I'm wondering if I'm wasting my time. Has any one ever seen AJAX+SSL cause encoding problems (like the one I describe above)?

Any advice or suggestions are greatly welcomed.
Hmmm ... well I'm certainly no expert in this field, but I think I grok the basic problem.

Consider the classic example of a non-thread safe operation:
someStaticInt = someStaticInt + 1;
Without some additional code to perform synchronization, running the above statement concurrently in multiple threads results in a non-deterministic result. The crux of the problem is that the operation at large involves three steps:
a) fetch the current value of someStaticInt
b) compute the value of someStaticInt + 1
c) assign the computed value to someStaticInt
So even though the programmer only writes one line of code, there are multiple steps involved ... and there's no guarantee that a thread won't be interrupted after, say, step b.

To me, it sounds like

the compiler is allowed to update the shared variable to point to a partially constructed object before A has finished performing the initialization

is just an elaborate (if exact) way of saying that the single line of code:
helper = new Helper();
... really translates to multiple steps. As with the classic example, an operation that translates to multiple (non-atomic) steps is vulnerable to synchronization problems when performed in a multi-threaded environment.
Jeanne's suggestion sounds like a good place to start. If you want to capture the ordered URLs for a full round of game play, then adding a javax.servlet.ServletRequestListener to your application will make that step easier.
14 years ago
If you're feeling adventurous, you can 'roll your own' session monitor by implementing a class that implements the javax.servlet.http.HttpSessionListener interface.
14 years ago
You can keep track of current sessions in a single web application running on a single application server by implementing an HttpSessionListener: javax.servlet.http.HttpSessionListener
15 years ago

how would i retrieve the role and user information from a database, rather than using and xml file?

... you might find the "Defining a JDBCRealm" section of this article useful:

15 years ago
Update for Tomcat 6 ... If you want to use EVAL_BODY_BUFFERED as (wisely) suggested above, you may need to grant this permission in your catalina.policy file:

permission java.util.PropertyPermission "org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER", "read";
Will there be any overlap in the data you're considering storing in the session? In other words, will users A and B both end up storing some of the same data in the session? If so, you might consider storing some common data types at the application level.
15 years ago
I can recommend this excellent paper for background on detecting partial duplication within files.
15 years ago