Swapnil Shroff

Ranch Hand
+ Follow
since Mar 07, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Swapnil Shroff

Thats what I'm doing, my FutureTaskWithExpire maps to your CacheEntry. But yes you are correct instead of storing the time the entry would expire, I should just store the lastAccssed time and then calculate if expired in hasExpired or isResultExpiredMethod. That way - get method will have some less work to do and the calculation would be done in sweeper thread.
I'm trying to extend the cache implementation given in book Concurrency in Practice(by Brian Goetz).

I want to extend the cache such that if any entry is not accessed in 10 seconds then it should expire. i.e removed from cache.

For this I have extended Future and FutureTask as below






As seen above I'm overriding the the get method to calculate the expiration time.

And in the main cache Class i.e Memorizer I will start a new thread that will periodically scan the entries and remove entries where isResultExpired returns true.

I just wanted to know if this implementation would work or there is some bug in my code?

Note I should also override get with timeout, however to keep is concise I have omitted that.

Thanks
We have a classic problem of multiple processes subscribing to same dataset from database. To solve this we are planning to implement a caching mechanism using ehcache. The solution would have a server component that maintains the cache and the client component that uses the cache.

Hence it would be quite useful if you have any references to examples on how to use remote caching in ehcache.

Thanks & Regards
Swapnil
13 years ago
While working on an issue recently, I came across a problem where I thought that cloning a hashmap(having some integers and strings) would solve the problem.
However when I read more about what the method does, I found that it does a shallow copy of hashmap object and the objects are not actually copied.
Hence I thought to iterate through the hashmap and call clone of each key-value pair, but i found out that String and Integers (in fact all the wrapper classes) doesn't support clone.

My question is - why these classes don’t support clone method and what are the other intelligent ways to clone object of these classes?

Also it seems weird that clone method is object class and not in Cloneable object.
What is the reason behind this design decision?

14 years ago

the throw keyword is always used with the new keyword...



Sudipto, It is not mandatory to use new with throw but it turns out that majority of cases we have to throw new exception based on some logic.

Samrat , finally always supersedes the try catch block.
For example
1. execute the try block
2. if any error then go to catch block and then finally block
3. if no error than try and finally.

Also, a method can either throw a exception or return a value but not both at a time.. so from this and point 2 you can conclude the behavior.
If core java is only option available to you then I would prefer so bring down the batch size down and free the resource as soon as processing is done.
For example, free result set once you build hash table. free hash table objects as soons as you write it to file.

Also why do you need hash table.. you can just read from resultset process the date columns and write to file..that way you would save some memory.
15 years ago
Wait and notify concept is always linked to threads but they are methods in Object, not Thread. If you try to use them on a
Thread object you may not get the results you expect.
I will try to explain here-
Producer and Consumer is a classic example however to make it interesting consider following scenario below

We have a Bar Object and 3 working thread (2 bar tender and 1 helper)

Object Bar has 2 methods getGlass and putGlass and List of glasses. When a bar tender wants a glass it will call getGlass method of bar object and helper calls putGlass to place a glass on shelf.

Each time getGlass is called a glass is subtracted from list similarly each time put is called glass is added to List.

Now when list becomes empty and there are no glasses in the bar then any bar tender that calls getGlass would be asked to wait. And when helper thread calls putGlass then all bar tender thread gets notified as they are waiting. You can assume that the notifying mechanism is internal to restaurant(jvm )

For your example, the right way would be-


hope it helps
If its a checked exception then it will give a compile time exception..
even thing now is there a product called JPurify.
or is it Rational Purify Plus
Hi All,

How is JPurify as a product? Can it be used in Maintainence Application or is it only good for Developmment projects
Thanks
I am hoping that it doesn't cause me my job .
But the fact that it is a ext api libraries which are optional(as per sun)
http://java.sun.com/javase/6/docs/technotes/guides/extensions/

suggests me that the base installation is not dependent on the packages in jre/lib/ext dir.
16 years ago
reformatting the date and not to use locale dependent dateformat seems the ideal solution.
But the problem is that the code is in production and would need a long cycle of dev and fix.

setting a different locale doesn't work as I changes the japaneese string on the screen to english.

Maneesh is correct, the app makes dynamic query based on the input and executes on db so no java.sql.Date.

As a short term solution we have removed the localedata.jar from the ext folder. Java says that it is a optional api so I am hoping that it works
16 years ago
I am working on a legacy swing application that I have recently migrated to java 1.6 from 1.3. The application is simple client/server app with clients in tok but db server in london.
My problem is, when client launches the app in ja_JP locale it formats the date vale to dd MM yyyy. Now this format is not recognized by database and hence throws an error. The same code works fine if the locale is set to en_GB as the date format is dd MMM yyyy.

I have debugged this and found that java6 uses extention jars(ext/localedata.jar) to get the default date format for each locale. So I tried to remove this jar and the app seems to be working fine.

However, I have a doubt if the removal will fail at some other place?Should I watch for any other possibility?

Please reply..Thanks
16 years ago

The "-version" option simply causes the JRE version to be printed; it does not cause any change in the way the JRE works.



I think -version option does more than that
From java command


JREs are backwards-compatible: anything that ran on 1.3 should also run on 5.



JRE 5 does not have assured compatibility with 1.3. I tried my code(its a legacy code with heavy swing/awt use) compiled on 1.3.1_19 to run on 1.5 but it gives me wired exceptions.

-version option gives a way to run code compiled with olderversion to run on latest version. I tried doing it eclipse and was successful . however I want to so similar thing on command prompt.

Thanks
16 years ago
Also, what does the -version:<> does.
Does it run current jre as target version
16 years ago