Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reading file and validate data issue

882656Aug 16 2011 — edited Aug 16 2011
Hey all !

I'm developing an application where I get info from a file and I have to validate the data. What I want is to improve performance. Now I'm thinking about using a PRODUCER-CONSUMER approach to improve performance, having 1 thread reading data from file and having 1 thread validating data.

What do you think? Is there a better approach on this kind of problem?

Thanks in advance :D

Comments

Nigel Deakin-Oracle
Publisher send some ObjectMessage(any pojo) in to the queue. let there are 5 message in queue.
When Consumer is wake up it reads the queue and sort all the queue objects (on the basis of some property of pojo class i.e entry_date, priority_level) and pick the top one and process and leave the rest in to the queue. And do the above thing again and again until the queue is empty.

So my question is that is it possible to implements?if yes the give some way.
You can't in general consume arbitrary messages from the middle of a queue. It's a queue and is designed for messages to be delivered in order.

However the JMS "message selector" feature may be worth investigating. This allows you to define a filtered view of the queue on the basis of various message header properties. Please consult any JMS textbook or your product documentation for more information.


Nigel
gimbal2
nigeldeakin wrote:
You can't in general consume arbitrary messages from the middle of a queue.
The OP does specifically state taking from the top of the queue, not "in the middle" as you suggest. I think the basic question is how to sort messages on the queue and only process one message at a time. Consuming messages synchronously seems a solution to the latter requirement, like this basic tutorial demonstrates:

http://java.sun.com/developer/technicalArticles/Ecommerce/jms/

But that does not cover sorting. I'm not too familiar with JMS at that level, but I believe that is something that would be a vendor specific feature and in general not a good requirement to have when messaging is involved. The power of the system is in the ability to deal with messages in any order, synchronously or asynchronously.
Nigel Deakin-Oracle
gimbal2 wrote:
nigeldeakin wrote:
You can't in general consume arbitrary messages from the middle of a queue.
The OP does specifically state taking from the top of the queue, not "in the middle" as you suggest. I think the basic question is how to sort messages on the queue and only process one message at a time. Consuming messages synchronously seems a solution to the latter requirement, like this basic tutorial demonstrates:

http://java.sun.com/developer/technicalArticles/Ecommerce/jms/

But that does not cover sorting. I'm not too familiar with JMS at that level, but I believe that is something that would be a vendor specific feature and in general not a good requirement to have when messaging is involved. The power of the system is in the ability to deal with messages in any order, synchronously or asynchronously.
If the OP wants to change the order of messages on a queue prior to consuming them then this isn't a feature provided by JMS.

Nigel
gimbal2
Not by the specification, no. But there are multiple implementations out there with vendor specific features. Perhaps something can be found there, but that doesn't change the fact that it is probably not a good idea to need something like that. It smells like an architectural mistake.
EJP
I find it pretty hard to believe that any vendor would supply an operation that sorted a queue in situ. What happens if another message arrives during the sort? or after the sort but before the client takes off the first message? It just cannot work correctly, because it can't be atomic.

The OP should be using a message filter as suggested earlier.
DrClap
Well, it would just require inserting new objects into the right place into the queue, which is hardly "sorting". But yeah, it would have to lock out both reads by consumers and writes by producers while it was doing that insertion.

However I find it hard to believe that any vendor would provide this feature strictly for ObjectMessages and allow comparison based on properties of the enclosed objects. Sounds too unlikely for even the IBMs of the world to contemplate.
EJP
No, the OP is talking about sorting existing messages in situ, not ordered insertion. It was suggested that a vendor might provide such a thing. I don't believe it is even feasible let alone desirable.

Maybe the OP should just reconsider (or consider) his notion of queue priority.
gimbal2
EJP wrote:
No, the OP is talking about sorting existing messages in situ, not ordered insertion. It was suggested that a vendor might provide such a thing. I don't believe it is even feasible let alone desirable.
In partial defense, I base my hasty conclusions on a Google search pointing at JBoss messaging implementations that can do at least some form of sorting, but I didn't investigate through to actually be able to claim that what I found relates in any way to this thread. My main point was to investigate implementation specific features when you need to do something that the API doesn't provide.
linkin
Thanks all of you.

Thanks & Regards
1 - 9
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 13 2011
Added on Aug 16 2011
2 comments
667 views