0 Replies Latest reply on Apr 26, 2011 9:50 AM by Francis Drake

    Resource blocked

    Francis Drake Newbie

      hi,


         from time to time my seam application suffer from perfomance reasons. I have made java application to make dumps of JBoss server, when there is more than 10 concurrent database connections and what I spotted, most of the threads is in state blocked and stack trace shows that my class LanguageTools is involved. I use this class to get or set language which customer is using to browse my web page. Here's the class:





      package com.mypage.tools;
      
      import java.util.Locale;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.international.LocaleSelector;
      
      @Name("languageTools")
      public class LanguageTools {
           
          @In(create=true) private LocaleSelector localeSelector;
          @In(create=true) private Cookies cookies;
      
          public LanguageTools() {}
      
          public void setLangDa() {
              localeSelector.setLocale(new Locale("da", "DK"));
              localeSelector.select();
              cookies.setCookieValue("Language", "da_DK", cookies.LANGUAGE_COOKIE_MAX_AGE);
          }
      
          public void setLangEn() {
              localeSelector.setLocale(new Locale("en", "US"));
              localeSelector.select();
              cookies.setCookieValue("Language", "en_US", cookies.LANGUAGE_COOKIE_MAX_AGE);
            }
      
          public void setLangPl() {
              localeSelector.setLocale(new Locale("pl", "PL"));
              localeSelector.select();
              cookies.setCookieValue("Language", "pl_PL", cookies.LANGUAGE_COOKIE_MAX_AGE);
            }
      
          public String getLanguage() {
              return localeSelector.getLanguage().toUpperCase().trim();
          }
          
          public String getLanguage(Locale locale) {
               if(locale != null) {
                    return locale.getLanguage().toUpperCase().trim();
               } else {
                    return localeSelector.getLanguage().toUpperCase().trim();
               }
          }
      
          public String getLanguageLowerCase() {
              return localeSelector.getLanguage().toLowerCase().trim();
          }
      
          public void setLanguage(String languageCode) {
              localeSelector.setLanguage(languageCode.toUpperCase().trim());
          }
      
          public String getCountry() {
              return localeSelector.getCountry();
          }
      
          public void setCountry(String countryCode) {
              localeSelector.setCountry(countryCode);
          }
      
          public Locale getLocale() {
              return localeSelector.getLocale();
          }
          
          public Locale getLocale(String languageCode) {
               languageCode = languageCode.trim().toLowerCase();
              if(languageCode.startsWith("da")) {
                  return new Locale("da", "DK");
              } else if(languageCode.startsWith("pl")) {
                  return new Locale("pl", "PL");
              } else {
                  return new Locale("en", "US");
              }
          }
      
          public void setLocale(Locale locale) {
              localeSelector.setLocale(locale);
          }
      
          public void setLocaleForLanguage(String languageCode) {         
               if(languageCode == null || languageCode.length() == 0) {
                    return;
               }
              languageCode = languageCode.trim().toLowerCase();
              if(languageCode.startsWith("da")) {
                  setLangDa();
              } else if(languageCode.startsWith("pl")) {
                  setLangPl();
              } else {
                  setLangEn();
              }
          }
      }



      I have read some performance posting and I wonder if I can tune this class a bit? The problem is that 2 most often methods are getLanguage and getLanguageLowerCase, so I can not use @BypassInterceptors amd use context lookup instead of injecting LocaleSelector. Or maybe I can.


      Thanks a lot for any tip.
      Michal