大地图冻结我的程序

时间:2017-10-03 11:49:58

标签: java

我有一个大的Map,我存储了一些对象。地图很大:它有大约200k个对象。当我尝试运行一些需要读取地图值的方法时,程序会冻结。当我调试它时,似乎我的IDE是“收集数据”(图片)。它从未完成任务。

enter image description here

我有16GB的RAM。 我该怎么做才能加快速度呢?

2 个答案:

答案 0 :(得分:0)

我的性能问题大约有6100万个。

java -Xms12G -Xmx13G BreakingMaps

我使用static class Key{ final long l; public Key(long l){ this.l = l; } @Override public int hashCode(){ return 1; } @Override public boolean equals(Object o){ if(o!=null && o instanceof Key){ return ((Key)o).l==l; } return false; } }

运行程序

我怀疑你的问题不是地图,而是地图周围的情况。如果我编写相同的程序,但使用具有哈希码colisions的类,则程序无法处理200K元素。

Package Failed_Scripts_SignUp;  
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import Object_Repository.Config_Reader;

public class Signup_MethodDriven_Framework {

    WebDriver driver;
    Config_Reader  con_reader=new Config_Reader();

    @Test(priority=1)
    public void Setup() throws InterruptedException {
        System.out.println("launching chrome browser");
        System.setProperty("webdriver.chrome.driver", con_reader.getChromepath()+"chromedriver.exe");
        driver = new ChromeDriver();                            
        driver.manage().timeouts().implicitlyWait(150, TimeUnit.SECONDS);
        driver.navigate().to("http://mobactech.com/tms");
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(150, TimeUnit.SECONDS);
        BaseClass_TMS_Signup baseclass=new BaseClass_TMS_Signup(driver);
   driver.findElement(By.className("signup")).click();                                      
                driver.manage().timeouts().implicitlyWait(150, TimeUnit.SECONDS);
                baseclass.enter_username("deepika");
                baseclass.enter_mail("deepika@mobactech.com");
                baseclass.enter_mobile("9876543234");
            }
        }


        // baseclass.java
        package Failed_Scripts_SignUp;
        import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.WebElement;
        import org.openqa.selenium.support.FindBy;
        import org.openqa.selenium.support.PageFactory;
        import org.testng.annotations.AfterClass;
        import Object_Repository.Config_Reader;

        public class BaseClass_TMS_Signup {

             WebDriver driver;

            Config_Reader  con_reader=new Config_Reader();

            public BaseClass_TMS_Signup(WebDriver driver)
            {
             PageFactory.initElements(driver, this);
            }

            @FindBy(xpath="//input[contains(@name,'user_name')]")
            public WebElement username;

            @FindBy(xpath="//input[contains(@name,'user_email')]")
            public WebElement useremail;

            @FindBy(xpath="con_reader.getusermobile()")
            public WebElement usermobile;

            @FindBy(xpath="//input[(@type='checkbox')]")
            public WebElement selectradio;

            @FindBy(xpath="//input[contains(@name,'submit')]")
            public WebElement signup;

                public void enter_username(String num1) {
                username.clear();
                username.sendKeys(num1);
            }

            public void enter_mail(String num2) {
                useremail.clear();
                useremail.sendKeys(num2);
            }

            public void enter_mobile(String num2) {
                usermobile.clear();
                usermobile.sendKeys(num2);

                selectradio.click();
                signup.click(); 
            }

            @AfterClass
            public void close()
            {
                driver.close();
            }
        }

        // objectrepository
        ChromeDriver= D:/admin/
        FirefoxDriver= D:/admin/
        Signup.Tab=//li/a[contains(text(),'Sign up')]
        User.Name=//input[contains(@name,'user_name')]
        User.EmailAddress=//input[contains(@name,'user_email')]
        User.Mobile=//input[contains(@name,'user_mobile')]
        User.AgreeTerms=//input[(@type='checkbox')]
        User.SignUpButton=//input[contains(@name,'submit')]
        SignIn.Tab=//li/a[contains(text(),'Sign in')]
        User.Password=//input[contains(@name,'user_password')]
        User.SignInButton=//input[contains(@name,'submit')]
        URL=http://mobactech.com/tms

       // ConfigReader.java
        package Object_Repository;
        import java.io.File;
        import java.io.FileInputStream;
        import java.util.Properties;

        public class Config_Reader {

            Properties pro;

            public Config_Reader()
            {
                File src=new File("./Configuaration/Config.property");
                try {
                    FileInputStream fis=new FileInputStream(src);

                     pro=new Properties();

                    pro.load(fis);

                } catch (Exception e) {

                    System.out.println("Exception is " +e.getMessage());            
                }       
            }

            public String getChromepath()
            {
                String path=pro.getProperty("ChromeDriver");
                return path;
            }

            public String getURL()
            {
                String url=pro.getProperty("URL");
                return url;
            }

            public String getsignuptab()
            {
                String tab=pro.getProperty("Signup.Tab");
                return tab;
            }

            public String getusername()
            {
                String name=pro.getProperty("User.Name");
                return name;
            }

            public String getuseremail()
            {
                String email=pro.getProperty("User.EmailAddress");
                return email;
            }

            public String getusermobile()
            {
                String mobile=pro.getProperty("User.Mobile");
                return mobile;
            }

            public String getAgree()
            {
                String agree=pro.getProperty("User.AgreeTerms");
                return agree;
            }

            public String getsignupbutton()
            {
                String signup=pro.getProperty("User.SignUpButton");
                return signup;
            }

            public String getsignintab()
            {
                String agree=pro.getProperty("SignIn.Tab");
                return agree;
            }

            public String getpassword()
            {
                String agree=pro.getProperty("User.Password");
                return agree;
            }

            public String getsigninbutton()
            {
                String agree=pro.getProperty("User.SignInButton");
                return agree;
            }   
        }

答案 1 :(得分:-1)

查看this - 作为解决方案,您可以增加应用的堆大小:

  

java -Xmx6g myprogram。

但它不是很好。我建议你尝试重新设计数据处理方法。也许你可以在获取数据之前应用一些过滤来减少数据大小或在数据库级别上实现一些计算。