File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Number of classes in struts. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Number of classes in struts." Watch "Number of classes in struts." New topic
Author

Number of classes in struts.

Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
Hi All,

I did a sample project in core_java contains 4-5 classes. Now I've to integrate that to Web-App Jee project(Using struts-2 framework). Now in struts-2
1) Action
2) model and
3)Business Services will be there.

In my case user inserts nothing, so model not-required. Business Service class will talk to DB. But I've 4-5 class. So the option I've left with is to make all those 4-5 class as action and chain/redirect them in my struts.xml. Problem is one class initiating threads. Is there any problem by creating threads in Web-App.

Instead of making those 4-5 classes as action-class, Is there any better solution?

Thanks:
Ramakrishna K.C
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
1.) Do not worry about the number of classes when designing a solution. Design it the best way possible and only worry about number of classes when it becomes an issue.
2.) No you should not start your own threads in code that is run by container. The container should start and maintain all threads. Why are you starting the threads? What do they do?
Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
I'm doing mini-Web Crawler. So Threads are must and should(according to the requirement). But, How to make container to Create, start and stop/sleep threads?

Thanks:
Ramakrishna K.C
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
If you are on EE6 you can see if the TimerService can help.
If not then look at your container's documentation to see if it provides an executor service and use that. (e.g some Jboss versions have quartz)
Otherwise you might need to start a thread pool on container startup in a ServletContextListener using the Executors class and shut it down on context shutdown. If you go down this route then consider making those threads daemon as well.

Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
I red some of the concepts about whether to creating threads in Jee or Not. So finally I got that Container will manage everything. But, I think if I make the main thread to run normally (which maintained by Container) and make others threads(created by main thread manually) to destroy after its job completed will not cause any problem? I don't think so for NOW. Is this bad idea or what? By using Quartz, will it maintains all threads? Please give some sample code. So that I can get logic and also Idea about how threads will finish by Container.

Thanks:
Ramakrishna K.C
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
Ramakrishna Udupa wrote:But, I think if I make the main thread to run normally (which maintained by Container) and make others threads(created by main thread manually) to destroy after its job completed will not cause any problem? I don't think so for NOW.
What do you mean by main thread? What is wrong with using a solution from the three I posted above?
Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
No problem with those solutions. Just asked. If you have some sample code please post.

Thanks:
Ramakrishna K.C
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
I don't know which approach you are going to use so what code would I post? Also, it's better to get a tutorial/manual that explains the approach that you want to use not just grab some code samples to stick in.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8908
    
    8

Ramakrishna Udupa wrote:I'm doing mini-Web Crawler.


Why are you housing a web crawler within a JEE container?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
@Joe Ess

Is there any better solution to put this out of container (Best Practices)? Please suggest me.

Thanks:
Ramakrishna K.C
Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
@E Armitage

I searched for Quartz-Scheduler and downloaded it. Installation is necessary? In Quick-start page, they told to install. But I got ZIP file(no .exe file to install), I unpacked that. Then I've to those .jars in my class path. Only those thing I've to do right?

Thanks:
Ramakrishna K.C
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
Ramakrishna Udupa wrote:@E Armitage

I searched for Quartz-Scheduler and downloaded it. Installation is necessary? In Quick-start page, they told to install. But I got ZIP file(no .exe file to install), I unpacked that. Then I've to those .jars in my class path. Only those thing I've to do right?

Thanks:
Ramakrishna K.C

Are you using jboss 5.X then? If you are then you don't have to download anything because it already comes with quartz. See my reply above again.
Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
Jboss is an Application Server just like Tomcat which hosts the Web-App (As per my knowledge). I'm using tomcat, I think no need of JBoss (I guess). But, I've to write Quartz.xml in my Web-App and tomcat should read that. I don't know that much about Jboss except that it is App-server. Jboss which internally contains quartz. Correct right?

Thanks:
Ramakrishna K.C
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8908
    
    8

Ramakrishna Udupa wrote:
Is there any better solution to put this out of container (Best Practices)? Please suggest me.


The "best practice" if one did not need web-container features (i.e. serving web pages) and required features forbidden in JEE applications (i.e. independent threads) would be to make it a stand-alone application.
Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
@Joe Ess

Can you please elaborate? Explain simple, effective way of placing my web-crawler in my project. (At Present, its in Core-java. I'm trying to integrate with Jee.)

I got that you are telling to make that Crawler(core-java) stand-alone. But, the requirement is like, when the user wants to stop crawl he can and giving another seed URL to the crawler to crawl. UI in Jee and crawler in Core-java. How to connect those. I got struck in past 3 days. Please give me head-slap with good idea.


Thanks:
Ramakrishna K.C
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8908
    
    8

Ramakrishna Udupa wrote:I'm trying to integrate with Jee.


Why?

Ramakrishna Udupa wrote:
But, the requirement is like, when the user wants to stop crawl he can and giving another seed URL to the crawler to crawl. UI in Jee and crawler in Core-java.


Why not make a GUI in Swing?
Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
@Joe Ess

you mean, Stand alone application with swing and crawler? yup. good idea. So, this is the good one according to you? Let me discuss with my team and after that I'll tell you.
Thanks for nice idea.

Thanks:
Ramakrishna K.C
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8908
    
    8

Ramakrishna Udupa wrote: So, this is the good one according to you? Let me discuss with my team and after that I'll tell you.


That would be determined by your requirements, which you have not shared with us. If you don't need JEE features, you don't need a JEE container.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Number of classes in struts.