Yaroslav Chinskiy

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

Recent posts by Yaroslav Chinskiy

Hi,

Is it possible to create private cache and private deployment.properties?

Lets say I have full control over JRE on the client site.
The JRE is not default for the system and is used in conjunction with my JNLP app only. The idea is to completely remove dependencies on local JRE, javaws version, deployment.properties etc...

1. I would like to be able to enable tracing/logging for my app without affecting other JNLP apps already installed.
2. I would like to set my JNLP app in a separate cache location.
14 years ago
All,

I am trying to write a simple message broker that can handle in-time and delayed requests.
I wanted to use Executors.newSingleThreadExecutor() combined with a Callables.

What I found is that performance degrades significantly if I use just in-time requests.

Request:


Broker:



TestCode:


My test includes 10 threads constantly pumping requests in the broker and timer that puts delayed message every 200 millsec. The throughput is:
Time: 5 sec
# of delayed messages: 24
# of messages: 356732
Av time: 0.1366528749551489

If I modify the broker to use 2 executors for in-time and delayed requests, the performance is significantly better:


Output:

Time: 5 sec
# of delayed messages: 24
# of messages: 434754
Av time: 0.11181648599102487

Any idea why 2 threaded app with 2 queues that have to be linked is faster than single threaded with one priority queue?
Any way to optimize?


15 years ago

Paul Clapham wrote:
Also, you're using a static Map to store the data, which means you've sort of written a Singleton object but don't have the proper controls, and you've created that map in the Attribute class and not in the AttributeList class where I think it belongs. So creating two of those objects (whichever class has the static variable) is going to lead you into trouble.



I tried to simulate enum. I want to use this class in different layers of the app which will communicate via simple messaging interface.
This is not singleton since it is expendable. However, I enforce "singleton property" for each attribute. I use combination of readResolve(), protected constructor and builder to enforce single instance of the attribute of a particular id.

Since I want users to extend it before use, it should be a class and not part of the AttributeList.


Also I think it's a bad practice to name something "SomethingList" when it uses a Map to store things. Calling it a "List" leads the user to believe he/she can add as many Dates as he/she likes, when it doesn't actually work that way.



I totally agree to that. Will rename ASAP.

My sample may have been misleading. I will have a message that will contain attributes. The messages will be exchanged through a message broker between different components of the app. I want complete decoupling and have similar system to NotificationCenter of Objective C.

Your container will work but has some limitations. I have to store this container in some sort of the collection.
I may have two containers with the same type. For example start Date and end Date. How will consumer distinguish them without extra information (some tag may be)?


On the other hand, we can create a class per type (similar to what I do with attribute). This may lead to a maintenance issue. Also, I will need some construct for this containers to make all of them immutable/mutable. I would like to keep it simple and use a dictionary where anyone can put/get data. This concept is easy to understand and use but will lead to type safety issue. For example, if I use a map and decide to use String for data while consumer was expecting another object, the issue will arise at run time only. I want to know about it at compile time and not hear about it from production env.

15 years ago
All,

I am trying to write a heterogeneous map where I can get compile time type safety.

The goal is to have a map of attributes where a producer can put data in and consumer can retrieve it without casting.
I am not using any messaging API. This will be used in pure JAVA app without any fancy frameworks.
What do you think about this approach:

Some of my colleges say that type safety if overrated and we should use regular Object->Object dictionary. This approach will assume that users know that source of information and can appropriately cast it at run time. Do you think it is batter to keep it simple or enforce type safety?


Attribute class (I can not use enum. I want to use this as an API and do not want anyone to stick new attributes in the jar once it was released. Unfortunately, enum does not support inheritance. User of the API can extend the attribute to create new keys.):


AttributeList(not using collection):


Simple test:


15 years ago
I vote for 1.

I think that readability of the code is more important than marginal optimization.
I am not an expert on JVM but most likely compiler or JVM will optimize performance anyway.

If code is hard to read/maintain it will lead to degrading performance in the long run....

15 years ago
Steve,

Good catch about final. I will fix it.
I wanted to use reflection as the last reserve. You code will accomplish what I need, but I was hoping for an easier solution. I guess who ever designed clone() did not intend it to be used outside of inheritance. sad.... :banghead:
15 years ago
All.

I have a delema , I want to create an immutable message. It is not strictly immutable, I just want to create a copy of a message before sending it.
The code looks similar to this:



But clone is protected so the code will not compile. Do you have any advice on how to clone properly?
15 years ago
Here is a simple example of singleton socket. The concept is there, implementation may be improved.
I am also putting some simple echo server to test this code.

I hope it makes sense.

Hi,

This is not a singleton. Specially if you use Java 1.4
Depending you your need you can do one of the following:

1. For 1.5 you can create an enum that will encapsulate the socket.
2. For 1.4 you can create a handler object that will create singleton (lazy) or define it as a static final variable.
3. Regardless of the pattern you choose to create singleton, abstract in and out streams to synchronized methods that will delegate to IO.
This approach is more flexible in the long run.
Thank you for the reply.

JNLP is not the best solution for me. It involves infrastructure and methodology change.

I am not looking for a solution that will enable application to cache/pre-load all data. I'm ok to fail the app if network is lost.

I wonder if there is a way to make JVM to reconnect to the classpath.

For example.
I you use Log4J and record to a file appender that point to thee remote drive, in case of the intermediate network failure, FD is lost and new log records are dismissed. Since I can detect the failure, I can easily reload log4j config and restore logging. (This is trivial solution ignorant to log4j abilities)

15 years ago
Hi,

I usually launch my app from a network drive. So all resources/JARs are stored on the network. Also, the app has embedded JVM.

I noticed that from time to time I get ClassNotFoundException. The reason is JVM does not preload all resources and fetches classes as needed. So if I have any intermediate network issue, JVM looses connection to the class path and can no longer load resources.


I am looking for some remedy to this issue. I am on JAVA 1.6.13 (or whichever is the latest)


Any advice?
15 years ago
Thanks for reply.

I already wrote cleanup() as a hack for the bug. but since app does not process all events in 1 thread. its a big change on the application and future developers should be forced to call it after they are done with the object. (boring)

The finilize on my java objects is called since they do not leak. I leak JVM memory.

Found this site:

http://devresource.hp.com/drc/resources/jmemmodel/index.jsp

If i add all messages to the static list and remove it from the static list in my java's finilize, it gurantees that the native object exist and i can deref it.

Makes bug fix localized to one class.

I still think there is a better way.
18 years ago
Hi,


Can someone point me to a good site for GC and finalize in Java 5?

I have JNI comm layer and its leaking memoey. My java heap is fine.

I noticed that data i get from JNi does not get deref. (that code is in finilize of swig wrapper of jni object)

So I wonder y it is not called and can I deref in my java objects once it is done with the jni event.

Thanks.
18 years ago
Hi,

I have an app that mixes java and JNI code. The heap of java is contatnt but memory allocation of the program is leaking.

Any advice to profile/debug the issue?

Any good source to learn about memory allocation for JNI and how it is garbage collected?

Thanks a lot.
19 years ago
Sameer,

Looks like I was wrong in interpretation of the docs.
Simple program proves ur point.


Thanks.