PaulN Pearson

Greenhorn
+ Follow
since May 23, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
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 PaulN Pearson

Aha, I've just found I can prevent this behaviour by changing the queuePrefetch value on the PrefetchPolicy of my ConnectionFactory from 1 to 0. What I don't understand is why the prefetch behaviour only comes into effect when I'm using transactions though. Also, if thread 1 has read a message (and presumably prefetched the next), I can pause this thread after it's transaction has been commited, and get thread 2 to read the second message instead. My understanding was that a prefetch policy greater than 0 would mean thread 1 would pre-allocate the two messages for itself and thread 2 wouldn't be able to consume either...?
13 years ago
We have an application which reads messages from a JMS queue in a multithreaded scenario using Spring. Simplified version of our Runnable.run() method, being executed by two threads, is as follows:



The problem we're seeing is that, sometimes, if one of the threads is between the getTransaction() (line 8) and commit() (line 21) calls (eg if the call to ingest(putTask) is taking a long time), the second thread will continually timeout while calling receiveAndConvert(), and return null, even if there are other messages waiting on the queue. The behaviour is not consistent, however, and sometimes the next message can be read regardless. I *can* get consistent behaviour (timing out and returning null) by running Eclipse in debug mode though. Does anyone know what we're doing wrong? Or is this a bug? I realise I've missed out some (irrelevant) methods, the field declarations, and the application context. If any of these are needed for someone to provide help I will happily post them.

Thanks,
Paul
13 years ago
Hi,

I'm working on a project involving ftp transfers. Client-side we're using org.apache.commons.net.ftp.FTPClient, and server-side we're using org.apache.ftpserver.

We've found that transfers sometimes timeout on the control connection. I've been trying to prevent this by starting a thread which periodically calls FTPClient.sendNoOp(). However the new thread blocks on this call until the prior call to FTPClient.storeFile(String remote, InputStream stream) completes. I think it's blocking while waiting for a response from the server, which appears not to process the NOOP until completing the STOR command. What am I doing wrong here?

Any help appreciated.

Paul
I have a long variable mapped to a database column, representing a date and time, in the form YYYYMMDDhhmm. So for example, midday today would be represented by the long value 200911051200L.

I need to be able to run queries using JPQL against each of the individual components - year, month, etc. In order to access the month, for example, I was hoping to be able to do "MOD(value, 100000000) / 1000000".

The problem with this is that the MOD function in JPQL appears to be only valid for integers, not longs. Alternatively, I tried doing the division first, which gave me a smaller number (one that would fit into an int), and then doing the MOD. However, the result of the division is still considered to be a java.lang.Long which can't be cast to an Integer. So that didn't work either.

Can anyone help me come up with a good way of doing these queries using JPQL? Changing the way data is stored in the database isn't an option. Doing the arithmetic in Java is undesirable.
Has anyone come across the following problem in JPA/Hibernate/Spring:

I have a persisted instance of a class MyClass which contains a Float instance variable, f, mapped to a database FLOAT type (either Oracle or H2). The value of f is 123.456.

I execute the following code:


Which prints "1" when run with an Oracle database (which is what I would expect), but "0" with H2.

What's more, on H2, when I remove the ROUND function and just query on "myClass.f = ?1" I get one result as expected, which suggests ROUND is the problem. But also when I leave ROUND there, and hardcode the parameter ?1 as "123.456" I also get one result, which suggests it's the setting of the parameter that's the problem!!!

Can anyone enlighten me as to what's going wrong here?
Thanks for your input. The reason I need this is that my objects are being stored in a database and are given an id when persisted. My equals method doesn't include the id, because I want to know if the objects have been seen before, and only persist them if they have not. So if I use my new object instead of the already-seen one stored in the Set, it will have the wrong id. I'm comparing with objects in memory rather than doing a database lookup for performance reasons.

I could use the Iterator, but it doesn't make use of the hashcode so will be less efficient. Using the HashMap and mapping an object to itself is certainly a solution I can use, thanks.
14 years ago
Thanks for your reply, however the contains() method does not help me locate the object I'm looking for. It's no good to just use myObject if contains() returns true, because myObject is not the same Object as the equal object in the Set. myObject == equalObject would be false.
14 years ago
Given a HashSet<Object> mySet, and an Object myObject, I would like to be able to retrieve the Object equalObject from mySet such that myObject.equals(equalObject) is true, if it exists. Is there a standard way of doing this? Of course, I could iterate through the set myself and find the equal object, but I would have thought the Set interface would have a method for doing this. Any help appreciated.
14 years ago
Yes, of course! I hadn't appreciated that this was in fact a many to many relationship. In fact, because I don't need my Role class to hold a list of users, I was able to map this as a one to many, but still using a join table. Many thanks for your help.
Here is a statement of my problem in simplified terms:

I have a User class. An instance of this represents a user of my application.

Each user has attributes such as userId, username, email address etc. The userId is the primary key for the USERS table.

Each user also has a List of roles, which is really just a list of Strings (such as "admin", data-migrator", etc). I have a USER_ROLES table, which has only two columns, USER_ID and ROLE. Since a user may have multiple roles, the primary key for USER_ROLES must be made up of both the USER_ID and the ROLE.

I have worked out how to do this by having a UserRole class, which has an embedded id class, whose attributes are the user id and the role. Is this the only way to do it? It seems a little pointless having a class whose only attribute is another class which contains the fields I want to persist. I appreciate that this would be sensible if there were other columns on my USER_ROLES table which did not form part of the primary key.

Any help in this would be much appreciated.

Thanks for your help. I am fairly new to Java, having studied it for less than a year, and to computation theory in general, coming from a mathematics background and recently having changed career to a development job. Hence the forum you pointed me towards was a bit on the technical side, and probably unnecessarily detailed for what I want to do.

The problem I was given at work was to implement a method which takes two arguments; a LinkedHashMap (which we'll call map) keyed by regex Strings mapped to an "id", and a String (str), and to return the id obtained from the "best match" key for str. The idea is that str represents a file path, and the regexes represent sets of paths which will each have a different id.

My first attempt at an implementation returns the id obtained from the first exact match. We would like to return the id associated with the most specific path. For example, our map may countain the keys "dir1/dir2/.*" and "dir1/.*". When matched against str = "dir1/dir2/file.ext" we would then use the first regex. Since it uses the first match, my implementation of course relies on the keys having been added to the map in order, from most specific to least. I would like my method to be able to reorder the regexes in case they have not already been added to the map in the correct order. The problem is that there may be, for example, different file extensions which str may have. The map may contain the following keys: "dir1/dir2/.*/file\\.ext1", "dir1/.*/file\\.ext1", "dir1/dir2/.*/file\\.ext2" and "dir1/.*/file\\.ext2".
We would then require that str = "dir1/dir2/dir3/file.ext1" used the first of these regexes, while str = "dir1/file.ext2" used the last. As in this example, the regexes may not possess a natural total order. I was hoping to reorder the keys into totally ordered subsets, each subset running from most specific to least, which is satisfied by the order of the four regexes given above. This wouldn't have been hard if there was a quick and easy way of checking whether regex A was a subset of regex B, but since this is not the case, I will need to find a solution which works for our needs.

I do not have full knowledge of the type of regexes we will be using, and I don't think this has been fully decided yet, so arriving at a good enough implementation may not be possible just yet.
16 years ago
Hi,

I have been looking into the java.util.regex package. What I need to be able to do is test if a particular regex A is a subset of a regex B. That is, test whether it is true that any String matching A also matches B. Does anyone have an idea how I might do this? Of course it is not simply a case of testing whether the String representation of A matches with B, for example the String "[ab]d" clearly does not match the regex "[abc]d", however the regex "[ab]d" is clearly a subset of "[abc]d".

Many thanks,

Paul
16 years ago