Hi All
I have a generic Collection and am trying to work out how I can sort the items contained within it. Ive tried a few things but I cant get any of them working.
I'm looking to create a new app from scratch and will probably use Spring MVC and possibly Spring Web Flow. The projects created by Spring Roo use Spring MVC and optionally Web Flow. What are some good alternatives for view technology, or is JSP with spring and jstl taglibs and jquery the way to go?
i would need to know the past 7 days record. i want to wrote a query for that in where condition. i have very basic knowledge in sqlite. Please help me for this query.
Hello,
i´m trying to get following tutorial to run and understand:
http://www.ibm.com/developerworks/web/library/wa-cometjava/index.html
In the example code which can be downloaded at the bottom of the page is everything in one class with two inner classes.
How can i make the the thread of "MessageSender" (Listing 3) visible to "The Weatherman" (Listing 4) so i can use it in the run method without using inner classes?
Thank you hansa
Reformulation of Question:
How to make the send-method of inner class MessageSender make accessible in ClassThatDoSomething.
Example-Code:
public class Example extends HttpServlet implements CometProcessor {
private MessageSender messageSender = null;
@Override
public void init() throws ServletException
{
// starts thread MessageSender
}
public event(CometEvent)
{
// Object of ClassThatDoSomething gets created started
}
private class ClassThatDoSomething {
public void start()
{
Runnable runnable = new Runnable() {
public void run(){
messageSender.send(message);
}
Thread thread = new Thread(runnable);
thread.start();
}
}
private class MessageSender implements Runnable {
public void send(String message) { //... }
public void run() { //...}
}
}
Hi!
I have a "plugin like" architecture and I want to create one instance of each class that implements a dedicated interface and put these in a cache. (To have a singleton-ish effect).
The plugins will be provided as jars and put into the app engine war file before the app is uploaded.
I have tried to use the ClassPathScanningCandidateComponentProvider as I'm using spring anyway, but this didn't work. The provider complained that it was not able to find the HttpServletResponse class file while scanning the classpath. I can't get around this, when I add the servlet jar, then I'll get of course problems, because the same jar is also provided by the GAE. If I don't, I'm getting the error above...
So I tried to add a static initialization code, but of course this doesn't work, because the class is initialized when it's instantiated for the first time. (Well I knew that but it was worth a try)
The last chance I currently see is that I create a properties file with all plugin classes when the package is created, but this requires writing of a maven plugin etc. and I'd like to avoid that.
Is there something that I am missing?
I was wondering if someone could point me to a good tutorial or show me how to graph the amplitude from a bytearray. The audio format I am using is: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame.
I am using Android 2.2 (API Level 8). The camera is enabled in the manifest. When I try the camera icon provided by the emulator model, it runs for a few seconds showing a gray box moving around a black and white checkerboard, then dies with the error message:
Sorry! The application Camera (process
com.android.camera) has stopped
unexpectedly. Please try again.
Trying again, of course, doesn't help. I am using the provided emulator camera to compare behavior with a camera application I am working on. Why does the android emulator camera stop unexpectedly?
Hi all,
My application is creating tables dynamically using entity mode as dynamic-map in hibernate properties. Tables are generally network devices having their attributes as columns of table. Requirement is if device is deleted from database, its table will be deleted. Can i drop table using hibernate tools dynamically?
Hi,
I want to write a buil.xml file that should open a new terminal for every client/server i want to use for testings.
How can i do that? i tried this code to run for example the 'ls' command on the newly created terminal. He created the terminal but doesn't run the cmd.
thanks.
I have a methor to return pagecontent of link
but when it run, alway return "Do not perrmisson ", plesea check it
here is code to return string pagecontent
public static String getPageContent(String targetURL) throws Exception {
Hashtable contentHash = new Hashtable();
URL url;
URLConnection conn;
// The data streams used to read from and write to the URL connection.
DataOutputStream out;
DataInputStream in;
// String returned as the result .
String returnString = "";
// Create the URL object and make a connection to it.
url = new URL(targetURL);
conn = url.openConnection();
// check out permission of acess URL
if (conn.getPermission() != null) {
returnString = "Do not Permission access URL ";
} else {
// Set connection parameters. We need to perform input and output,
// so set both as true.
conn.setDoInput(true);
conn.setDoOutput(true);
// Disable use of caches.
conn.setUseCaches(false);
// Set the content type we are POSTing. We impersonate it as
// encoded form data
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
// get the output stream .
out = new DataOutputStream(conn.getOutputStream());
String content = "";
// Create a single String value pairs for all the keys
// in the Hashtable passed to us.
Enumeration e = contentHash.keys();
boolean first = true;
while (e.hasMoreElements()) {
// For each key and value pair in the hashtable
Object key = e.nextElement();
Object value = contentHash.get(key);
// If this is not the first key-value pair in the hashtable,
// concantenate an "&" sign to the constructed String
if (!first)
content += "&";
// append to a single string. Encode the value portion
content += (String) key + "="
+ URLEncoder.encode((String) value);
first = false;
}
// Write out the bytes of the content string to the stream.
out.writeBytes(content);
out.flush();
out.close();
// check if can't read from URL
// Read input from the input stream.
in = new DataInputStream(conn.getInputStream());
String str;
while (null != ((str = in.readLine()))) {
returnString += str + "\n";
}
in.close();
}
// return the string that was read.
return returnString;
}
Hi,
can anyone help me ?
I wanto to play an audio file and whenever I press the stop button , the already played part of the file should be saved.
Unfortunately , what I get is an audio file (.wav) which actually is unplayable.
Thanks
//****************************
void play_cut() {
try {
// First, we get the format of the input file
final AudioFileFormat.Type fileType = AudioSystem.getAudioFileFormat(inputAudio).getType();
// Then, we get a clip for playing the audio.
c = AudioSystem.getClip();
// We get a stream for playing the input file.
AudioInputStream ais = AudioSystem.getAudioInputStream(inputAudio);
// We use the clip to open (but not start) the input stream
c.open(ais);
// We get the format of the audio codec (not the file format we got above)
final AudioFormat audioFormat = ais.getFormat();
c.start();
AudioInputStream startStream = new AudioInputStream(new FileInputStream(inputAudio), audioFormat, c.getLongFramePosition());
AudioSystem.write(startStream, fileType, outputAudio);
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}// end play_cut
//****************************
hello i am a student and i am doing my senior project it is about developing an application in j2me for scanning a barcode and extract the number of the barcode in a message to be send.
please i search the net but i cant found something usefull i am new at j2me if someone could help me with sourch code and how to create it i will be very thankfull my email is [email protected]
thanks in advanced
I have been observing extremely slow execution times with expressions with several lookaheads.
I suppose that this is due to underlying data structures, but it seems pretty extreme and I wonder if I do something wrong or if there are known work-arounds.
The problem is determining if a set of words are present in a string, in any order. For example we want to find out if two terms "term1" AND "term2" are somewhere in a string. I do this with the expresion:
(?=.*\bterm1\b)(?=.*\bterm2\b)
But what I observe is that this is an order of magnitude slower than checking first just
\bterm1\b
and just then
\bterm2\b
This seems to indicate that I should use an array of patterns instead of a single pattern with lookaheads... is this right? it seems wrong...
Here is an example test code and resulting times:
public static void speedLookAhead() {
Matcher m, m1, m2;
boolean find;
int its = 1000000;
// create long non-matching string
char[] str = new char[2000];
for (int i = 0; i < str.length; i++) {
str[i] = 'x';
}
String test = str.toString();
// First method: use one expression with lookaheads
m = Pattern.compile("(?=.*\\bterm1\\b)(?=.*\\bterm2\\b)").matcher(test);
long time = System.currentTimeMillis();
;
for (int i = 0; i < its; i++) {
m.reset(test);
find = m.find();
}
time = System.currentTimeMillis() - time;
System.out.println(time);
// Second method: use two expressions and AND the results
m1 = Pattern.compile("\\bterm1\\b").matcher(test);
m2 = Pattern.compile("\\bterm2\\b").matcher(test);
time = System.currentTimeMillis();
;
for (int i = 0; i < its; i++) {
m1.reset(test);
m2.reset(test);
find = m1.find() && m2.find();
}
time = System.currentTimeMillis() - time;
System.out.println(time);
}
This outputs in my computer:
1754
150
I have noticed from several web pages that apparently Spring 3.0 supports @Inject from JSR-330. As we would really like to use JSR-299 syntax for dependency injection in our libraries for both web apps and stand-alone applications, and have alternatives to Weld, it would be nice if Spring could do this.
Being a novice to Spring, I tried downloading the Spring Framework distribution and put all jars on the Eclipse build path. No Inject annotation so my existing test project using Weld did not compile.
Can this be done with Spring? What do I need to do to get it running?
(I am aware that Guice eventually will support this too. It is only in SVN for now, and if there is an official Spring release which can, that would be better.)
Hi there,
I'm writing a spatial data structure and I have a doubt about what's the best NODE implementation.
According to my design I have an abstract node entity and three classes which inherit from it: EMPTYNODE, FULLNODE, INTERNALNODE.
The first one has no particular data.
The second one has 1 reference to a generic element.
The third one has 2 references to other nodes.
I have found several ways to implement this situation (that I have already coded) but I can't decide what's the best.
The first solution that I have found is to use a single class Node that potentially performs all the operation in this way:
private static class Node {
private Elem elem = null;
private Node left = null, right = null;
public Elem getElem() {
assert isFull();
return elem;
}
public boolean isEmpty() {
return elem == null && left == null;
}
public boolean isFull() {
return elem != null;
}
public boolean isInternal() {
return elem == null && left != null;
}
}
The second solution is to write an explicit division by classes where every class offers only its methods. Obviously in this way we are obliged to perform several casts to the node objects.
private static abstract class Node {
public abstract boolean isEmpty();
public abstract boolean isFull();
public abstract boolean isInternal();
}
private static class FullNode extends Node{
private ITriangle elem;
@Override
public boolean isEmpty() {
return false;
}
@Override
public final boolean isFull() {
return true;
}
@Override
public final boolean isInternal() {
return false;
}
public Elem getElem() {
return elem;
}
}
The third one solution is to use the inheritance allowing every classes to offer all the methods, but the object type should by check by "isEmpty()" and similar methods. In case of wrong call we'll throw an exception.
private static abstract class Node {
public abstract boolean isEmpty();
public abstract boolean isFull();
public abstract boolean isInternal();
public abstract Elem getElem();
}
private static class Empty extends Node{
@Override
public boolean isEmpty() {
return true;
}
@Override
public final boolean isFull() {
return false;
}
@Override
public final boolean isInternal() {
return false;
}
@Override
public Elem getElem() {
throw new AssertionError();
}
}
What do you think about these three solutions?
Which one would you use?
Any other ideas?
Thanks for your help. Every idea will be appreciated.
I am building a swing application. At some point, I have to start an "animation":
...
jpanel1.setBackground(Color.Black);
Delay(milli)
jpanel1.setBackground(Color.White);
...
and so on.
The gui itself and all the logic behind it work.It is just this time depended color-changing that does not. I have read, that swing is not thread safe, but all the examples I found showed me how to start another thread (for example in the background) but never how to stop the current swing-gui thread.
I use Spring MVC and a regular JDBC.
I've just learned that I should separate business process into layers which are presentation layer, controller layer, service layer, and repository/DAO layer. Now suppose that I have an Entity called Person that can have multiple Jobs. Job itself is another entity which have its own properties. From what I gathered, the repository layer only manages one entity. Now I have one entity that contains another entity. Where do I "join" them? The service layer?
Suppose I want to get a person whose job isn't known yet (lazy loading). But the system might ask what the job of that particular person is later on. What is the role of each layer in this case?
Please let me know if I need to add any detail into this question.
I'm looking for a JVM profiler (preferably open source) so I can look at the heap and cpu usage of my personal website.
I've used Lambda Probe, and I like it because it provides a web interface for my remote Unix computer that has no display. I was wondering what else is available
Thanks,
I know that I can fade in a panel, by adding the alpha value to the background color & a timer. But how can I fade in a panel with child components (like a JLabel)?
EDIT
_fadeTimer = new Timer(40, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_alpha == 255) {
_fadeTimer.stop();
} else {
pnl_hint.setBackground(new Color(
bgColor.getRed(),
bgColor.getGreen(),
bgColor.getBlue(),
(_alpha += 1)));
pnl_hint.updateUI();
}
}
});
_fadeTimer.start();
I have a system which breaks a large taks into small tasks using about 30 threads as a time. As each individual thread finishes it persists its calculated results to the database. What I want to achieve is to have each thread pass its results to a new persisance class that will perform a type of double buffering and data persistance while running in its own thread.
For example, after 100 threads have moved their data to the buffer the persistance class then the persistance class swaps the buffers and persists all 100 entries to the database. This would allow utilization of prepared statements and thus cut way down on the I/O between the program and the database.
Is there a pattern or good example of this type of multithreading double buffering?
At the end of the README.txt file which is located in the example directory under solr, I find this line:
NOTE: This Solr example server references SolrCell jars outside of the server
directory with statements in the solrconfig.xml. If you make a copy of
this example server and wish to use the ExtractingRequestHandler (SolrCell),
you will need to copy the required jars into solr/lib or update the paths to
the jars in your solrconfig.xml
What does this mean?
Do I have to make some adjustment before uploading solr to my server?
Also, if you know, what is Solr-nightly:s difference to regular solr?
The tutorial states "solr-nightly.zip" but on their download section I cant find it.
How do I configure Hibernate so that each time I call sessionFactory.openSession() it connects with a new connection from the connection pool? The connection pool is managed by Websphere Application Server and is a JDBC Data Source.
Thanks