Java解析器时间问题

时间:2015-07-06 05:19:03

标签: java json parsing

我正在编写一个Java解析器,从ASANA服务器获取ASANA APP数据并对其进行解析,然后将其保存到本地数据库以获取自定义报告。我对执行此Java实用程序所需的时间有疑问。

我有Java解析器的这个子部分。当我运行它时,执行大约需要10秒钟。如果此代码在10秒内执行而不是一行,则在下面给出:

JSONObject Project_jsonObject = (JSONObject) Project_jsonParser.parse(Project_br);

此行在10秒内执行9秒。我怎么能减少这个时间。任何减少时间的技巧或提示或替代方案。请帮助我等待

        static File workDir = new File("C:/cygwin64/bin");
        static Runtime systemShell = Runtime.getRuntime();

        String project_request="curl -u 4cKDgv4O.L8Th7N8l7jADg3HRU44abmT: https://app.asana.com/api/1.0/projects/"+id_Project+"?opt_pretty";
        String project_cmd = project_request;
        project_cmd += " | grep 'OBJECT'"; 
        Process ProjectshellOutput = systemShell.exec(workDir+"/"+project_cmd, null,workDir);
        InputStreamReader Project_isr = new InputStreamReader(ProjectshellOutput.getInputStream()); 
        BufferedReader Project_br = new BufferedReader (Project_isr);

        JSONParser Project_jsonParser = new JSONParser();
        JSONObject Project_jsonObject = (JSONObject) Project_jsonParser.parse(Project_br);

        JSONObject projectdataObject= (JSONObject)Project_jsonObject.get("data");

        Long project_id =  (Long) projectdataObject.get("id");
        System.out.println("project id is: " + project_id);


        String project_created_at_dt = (String) projectdataObject.get("created_at");
        System.out.println("The project created at is: " + project_created_at_dt);

        String project_modified_at_dt = (String) projectdataObject.get("modified_at");
        System.out.println("The project modified at is: " + project_modified_at_dt);

        boolean project_public_status = (boolean) projectdataObject.get("public");
        System.out.println("project public status: " + project_public_status);

        String project_name = (String) projectdataObject.get("name");
        System.out.println("project name is: " + project_name);

        String project_notes = (String) projectdataObject.get("notes");
        System.out.println("project Notes are: " + project_notes);

        boolean project_archived_status = (boolean) projectdataObject.get("archived");
        System.out.println("project archived status: " + project_archived_status);

        JSONObject workspaceObj = (JSONObject) projectdataObject.get("workspace");
        Long workspace_id = (Long) workspaceObj.get("id");
        String workspace_name = (String) workspaceObj.get("name");
        System.out.println("Workspace id " + workspace_id + " with workspace  name " + workspace_name);


        String color = (String) projectdataObject.get("color");
        System.out.println("color : " + color);

        JSONObject teamObj = (JSONObject) projectdataObject.get("team");
        Long team_id = (Long) teamObj.get("id");
        String team_name = (String) teamObj.get("name");
        System.out.println("team id " + team_id + " with team name " + team_name);

1 个答案:

答案 0 :(得分:0)

您似乎正在使用JSON.simple库。根据{{​​3}},JSON.simple在大约140秒内解析了一个190 MB的文件。这与花费9秒来解析一个15 MB的文件是一致的。杰克逊更快,但只是勉强。所以我怀疑你能做些什么才能显着提高性能。