Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp

Paul Clapham

Sheriff
+ Follow
since Oct 14, 2005
Paul likes ...
Eclipse IDE Firefox Browser MySQL Database
Vancouver, Canada
Cows and Likes
Cows
Total received
54
In last 30 days
4
Total given
99
Likes
Total received
2430
Received in last 30 days
20
Total given
557
Given in last 30 days
20
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Paul Clapham

No, a web app doesn't necessarily need a database.

But more importantly, right now you're starting to design things and your requirements document says "It's a web app". If you hired me with that information I would be asking for more information rather than deciding what tools to use.

Likewise with your question about databases. If there was only one best type of database to use given the requirements "It's a database" then there would be only one type of database.
15 hours ago
You need to look at the beginning of your code where you (hopefully) have a list of "import" statements. One of them needs to import Flashcard from the package which it's in.

But wait... earlier you said

I updated the three files so the package name matches - two had a lower case F. Just to be clear, now that they're all under the same package there will be no importing of anything required, right?



Since the three classes are in a package, their source code should be in a directory whose name is the name of their package. And they should have been compiled so that their compiled versions are in that same directory (or at least a directory of the same name).
1 day ago

Ben Hutchenson wrote:I had thought that I needed to create objects with a unique name for every iteration (eg. FC0, FC1, FC2, etc) but I saw a post mentioning that the FC object is destroyed after each iteration...



Actually, FC is not an object in that loop. It's a variable name. The variable FC can contain a reference to an object of type Flashcard, but it is not an object itself. It's important to pay attention to the distinction because it's the idea of an object reference which gives Java a lot of its power.

So after each iteration, it isn't true that "the FC object is destroyed". What IS true is that the FC variable goes out of scope -- that means it can't be used outside of the loop.
1 day ago

Ben Hutchenson wrote:For my particular project I don't believe it's important to actually label each object in the ArrayList is there? When I say label, I mean declare each one with a variable name that uniquely identifies it (because I can just call deckEntire.get(int) right?



Yes, that's correct. And not just for your project, but for any Java program whatsoever. You can only access an object if something in your program has a reference to that object, but that certainly isn't limited to the code you wrote. Yes, the ArrayList is a list of references to objects, and you can get an object out of the ArrayList in exactly the way you said.

So the loop you wrote at the beginning of your code to put 7 objects into the list is just fine. However you could write it like this:



and as you can see, you don't even need a variable in your code at all. The new Flashcard object gets added straight into the ArrayList, which then holds a reference to it.

(I'm not suggesting that you ought to do that, your code is fine the way it is.)
1 day ago

paul nisset wrote:Regarding point [2] - It seems the take away point from Jeff and Paul C. is that I was looking for a value from a parent Node and not a child Node. ie "adminappv" is the  parent node of the text node that contains the value I was looking for.



Yes, that's right. A pretty common stumbling block when you're starting with XML. Let me warn you in advance about another XML gotcha:



In this XML fragment  there are three things:

1. An <adminappv> element which contains a text node.

2. A text node which contains only white space.

3. An <agencyid> element which contains a text node.

Many people overlook those white-space text nodes and write code which asks for "the seventh child of the root element". That leads to confusion because they didn't include the white-space text nodes in their count.

Jack Tauson wrote:1) User sends an Ajax request which triggers this stored procedure, and this SP is going to take long time.
2) While the request in Step #1 is still running, user could send another Ajax request ( I don't know if this is possible or not because I am using Ajax; I might have to use something else to handle (send and receive) asynchronous requests)
3) Similarly, if the above two requests are still RUNNING, user could send 3rd request and so on and so forth.



Not quite... the first Ajax request would trigger the stored procedure and then return immediately. That would leave some other process running the stored procedure; perhaps that Ajax request could send a JMS request to a consumer whose job is to run the stored procedure.

Subsequent requests would look to see at the status of the stored procedure, and return something like "The stored procedure is already running". Or if the status is COMPLETE, then they would return the result of the stored procedure.

To put it another way, the Ajax request would either trigger the stored procedure and let the user know that happened, or tell the user that the stored procedure is running, or return the result of the stored procedure. Based on the status code.

Sorry, I didn't understand this part completely. Are you referring that I could use multi threading instead of JMS here?



You could do that, but based on your description of the UI you wouldn't use multi-threading and you wouldn't use JMS either. Your UI would just have the ability to submit, query, or download but none of those things would block other UI features because they aren't long-running requests. (Long-running requests are a bad idea because they are likely to time out anyway.)

And it looks like having the stored-procedure processing task use JMS to send completion notifications may be unnecessary -- it doesn't look like there's anything in the UI which has to react immediately to that.

However it would be possible to have a web page in your Spring Boot app which just sat there and, once a minute or something like that, it would send a request asking whether the stored procedure was complete. No user interaction is necessary when you do that, it just sends the request repeatedly. It would be nice if the response could say "It's 72% complete" but it doesn't look like that's a possibility.
1 day ago
You're lucky that it's you who gets to choose the input format. In business programming it's not uncommon to have your customer insist on some g-dawful complicated format, and since they are your customer it isn't easy for you to tell them no.

paul nisset wrote:In light of that ,do you know why the following line in Eclipse hovering over element after the assignment ,I get " [adminappv:null] " when the text in the document's element is "0"?



It's because you are confusing the document element node with the text node which happens to be its only child. Sure, the value of that text node is "0", but the value of the element node which is its parent is not that. Consider this XML document:



What should the value of the "base" element node be? Well, there's a lot of things you might come up with but the fact is that the value of the "base" element node is null. And in fact the value of every element node is null. Frankly the whole concept of the "value" of a node isn't very useful.
Patrick, there's absolutely no reason to learn about applets now, since browser-makers have pronounced them to be software non grata. Maybe some versions of that book have an applet section and some don't, I don't know, but my advice is to just skip over that section if it's there. Really, there's no point in learning about applets.
2 days ago
That may work for you, but for somebody else (e.g. me) the fact that you have a variable named "sources" and another variable named "Sources" is horribly confusing. Please don't do that. Even giving a variable a name starting with a capital letter is a barrier to understanding, so please don't do that either.
2 days ago

Jack Tauson wrote:So maybe I could keep on pushing "RUNNING" message to the JMS queue until I get the message "COMPLETE". At the same time, my consumer will keep on checking
what's the latest message is on the queue, so basically, as long as the messaage on the queue is "RUNNING", the conde inside consumer won't do any thing. As soon as consumer sees that the message is "COMPLETE",
I could go ahead and do other stuff like grabbing data from other tables. How does this sapproach sounds? Please let me know if it's erroneous.



No, that would be pointless. Sending a JMS message which is guaranteed to be ignored? No. Just don't send that message. So then you're only sending the COMPLETE message, which is what I already suggested.

I think in this scenario, the UI would be tied to this particular request only,right? and until this request finishes, the user won't be able to do other things



I don't know why you would say that. Yes, the UI would be tied to that request. But you have to remember that I'm at a severe disadvantage in that I know absolutely nothing about this UI which you keep mentioning. And anyway what's to stop it from waiting for COMPLETE in one thread while doing useful user-related things in other threads?
2 days ago

Jack Tauson wrote:And as soon as the status in STATUS_CHECK table shows COMPLETE, I could have selected data from different tables so that I could send it to the UI for download.



It seems to me that this is the key requirement which you're trying to deal with, right?

I assume that the stored procedure is not set up to notify anything, it just sets that status code to COMPLETE and then terminates. Of course the termination could be considered to notify the task which is running the stored procedure, but it looks to me like that task is just running on its own and no other task is watching it.

So if you want to find out whether the stored procedure has finished, you have to look at the status code to see if it says COMPLETE. Nothing is going to tell you when it changes from RUNNING to COMPLETE, so it seems to me that you would just have to look periodically to see if the status is COMPLETE yet.

Based on my understanding of the problem, this is where my mind has led me.

However if you want to have JMS as part of the solution, then perhaps the task which runs the stored procedure could send a JMS message to some other task to notify it that the stored procedure has finished. Since the message itself means that the stored procedure has finished, it wouldn't actually have to contain any other information at all. In this case the STATUS_CHECK table become irrelevant.

And you talked about sending the data to "the UI". I'm assuming that this UI will be running unattended on some machine somewhere, since having a person watching it for several hours is impractical. Am I right? If that's the case then the UI could be the JMS message consumer, and it would update itself when it received a message.

On the other hand the unattended UI application could also look at the status code every (e.g.) 10 seconds and when it sees the status code is COMPLETE, it could then update itself. This seems easier to me than inserting JMS into the design.

Are any of these ideas on track?
3 days ago
I don't find them "deeply different" -- both of them are text-based formats which are used to store data in a structured way. And both of them prefer that structure to be a tree.

Admittedly they are different, in ways that Jeffrey has identified. However I tend to look at their similarities rather than their differences.
Could I suggest that, since of course you can't run this program without Java installed, that you try a different way of running it? Instead of expecting that "Cabin Assigner Pro.jar" will run the jar file, which apparently isn't always the case, why not try



instead? When you install Java on a Windows machine you know that the "java" command will be mapped to the appropriate java.exe. Whereas you don't know that the ".jar" extension will be mapped to whatever it is that runs executable jars.

The other advantage of that is that the "java" command gives you a command-line screen which doesn't go away when your Swing app runs, so if the app throws an exception you will see the stack trace.
3 days ago
Remember that a File object doesn't have to correspond to an actual file in your computer's file system.