Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6790327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:42:44+00:00 2026-05-26T17:42:44+00:00

i have a jsf application running on tomcat 6.0 and somewhere in the app

  • 0

i have a jsf application running on tomcat 6.0 and somewhere in the app i send e mails to some users.But sending mail slower than i thought, it causes lacks beetwen these related pages.

So my question is; is that a good(or doable) a way to give this proccess to another thread which i create, a thread that gets mail sending requests and put these in a queue and proccess these apart from main application.Hence the mail sending proccess would be out of the main flow and doesnt affect the app’s speed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:42:45+00:00Added an answer on May 26, 2026 at 5:42 pm

    Yes, that’s definitely a good idea. You should only do it with an extreme care. Here’s some food for thought:

    • Is it safe to start a new thread in a JSF managed bean?
    • Spawning threads in a JSF managed bean for scheduled tasks using a timer

    As you’re using Tomcat, which does not support EJB out the box (and thus @Asynchronus @Singleton is out of question), I’d create an application scoped bean which holds an ExecutorService to process the mail tasks. Here’s a kickoff example:

    @ManagedBean(eager=true)
    @ApplicationScoped
    public class TaskManager {
    
        private ExecutorService executor;
    
        @PostConstruct
        public void init() {
            executor = Executors.newSingleThreadExecutor();
        }
    
        public <T> Future<T> submit(Callable<T> task) {
            return executor.submit(task);
        }
    
        // Or just void submit(Runnable task) if you want fire-and-forget.
    
        @PreDestroy
        public void destroy() {
            executor.shutdown();
        }
    
    }
    

    This creates a single thread and puts the tasks in a queue. You can use it in normal beans as follows:

    @ManagedBean
    @RequestScoped
    public class Register {
    
        @ManagedProperty("#{taskManager}")
        private TaskManager taskManager;
    
        public void submit() {
            // ...
    
            taskManager.submit(new MailTask(mail));
            // You might want to hold the return value in some Future<Result>, but
            // you should store it in view or session scope in order to get result
            // later. Note that the thread will block whenever you call get() on it.
            // You can just ignore it altogether (as the current example is doing).
        }
    
    }
    

    To learn more about java.util.concurrent API, refer the official tutorial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a JSF application and I am running into some funny behavior
In my jsf application I have a button for sending mail. And each time
In a JSF 2 application, which is developed on tomcat, I have the following
I have some problem's with a simple application in JSF 2.0. I try to
I have a small JSF application where the user is required to enter some
I have a JSF 2 application which creates some SVG content. How can i
Basically i have a enterprise jsf application which shows some services to the user.
We have a JSF 2.0 application running under Glassfish 3.1.1 which has been moved
I have a JSF 2.1 (MyFaces) app running using several Session Beans (All the
I have simple JSF application. Everything works fine, but not navigation. It behaves like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.