[ 
https://issues.apache.org/jira/browse/MAPREDUCE-6542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15015463#comment-15015463
 ] 

zhangyubiao commented on MAPREDUCE-6542:
----------------------------------------

Hi,[~templedf].  Last patch I don't give a unit test.   
Beacause I confuse how to test the force concurrent access to the function 
GetFormattedTimeWithDiff()
I get the idea this days.  Under the Code ,You will find first  time1 was not 
the same in the Multithread and 
the second time1 was the same. Is it OK for the test ? Give me some 
advise,Thanks.

{code}
  @Test
  //Multithreaded Test GetFormattedTimeWithDiff()
  public void testGetFormattedTimeWithDiff() throws InterruptedException {
    ExecutorService exec1 = Executors.newFixedThreadPool(16);
    final long currentTime = System.currentTimeMillis();
    final long currentTime2 = currentTime - 30000;
    for (int i = 0; i < 20; i++)
      exec1.execute(new Runnable() {
        @Override public void run() {
          String time1 = StringUtils.getFormattedTimeWithDiff(dateFormat, 
currentTime, 0);
          System.out.println("time1 : " + time1);
          String time2 = StringUtils.getFormattedTimeWithDiff(dateFormat, 
currentTime2, 0);
          System.out.println("time2 : " + time2);
        }
      });
    exec1.shutdown();
    exec1.awaitTermination(50, TimeUnit.SECONDS);

    
System.out.println("---------------------------------------------------------");
    ExecutorService exec = Executors.newFixedThreadPool(16);
    for (int i = 0; i < 20; i++)
      exec.execute(new Runnable() {
        @Override public void run() {
          String time1 = StringUtils.getFormattedTimeWithDiff(fastDateFormat, 
currentTime, 0);
          System.out.println("time1 : " + time1);
          String time2 = StringUtils.getFormattedTimeWithDiff(fastDateFormat, 
currentTime2, 0);
          System.out.println("time2 : " + time2);
        }
      });
    exec.shutdown();
    exec.awaitTermination(50, TimeUnit.SECONDS);
  }
{code}



> HistoryViewer use SimpleDateFormat,But SimpleDateFormat is not threadsafe
> -------------------------------------------------------------------------
>
>                 Key: MAPREDUCE-6542
>                 URL: https://issues.apache.org/jira/browse/MAPREDUCE-6542
>             Project: Hadoop Map/Reduce
>          Issue Type: Bug
>          Components: jobhistoryserver
>    Affects Versions: 2.2.0, 2.7.1
>         Environment: CentOS6.5 Hadoop  
>            Reporter: zhangyubiao
>            Assignee: zhangyubiao
>         Attachments: MAPREDUCE-6542-v2.patch, MAPREDUCE-6542-v3.patch, 
> MAPREDUCE-6542-v4.patch, MAPREDUCE-6542.patch
>
>
> I use SimpleDateFormat to Parse the JobHistory File before 
> {code}
> private static final SimpleDateFormat dateFormat =
>     new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
>  public static String getJobDetail(JobInfo job) {
>         StringBuffer jobDetails = new StringBuffer("");
>         SummarizedJob ts = new SummarizedJob(job);
>         jobDetails.append(job.getJobId().toString().trim()).append("\t");
>         jobDetails.append(job.getUsername()).append("\t");
>         jobDetails.append(job.getJobname().replaceAll("\\n", 
> "")).append("\t");
>         jobDetails.append(job.getJobQueueName()).append("\t");
>         jobDetails.append(job.getPriority()).append("\t");
>         jobDetails.append(job.getJobConfPath()).append("\t");
>         jobDetails.append(job.getUberized()).append("\t");
>         
> jobDetails.append(dateFormat.format(job.getSubmitTime())).append("\t");
>         
> jobDetails.append(dateFormat.format(job.getLaunchTime())).append("\t");
>         
> jobDetails.append(dateFormat.format(job.getFinishTime())).append("\t");
>        return jobDetails.toString();
> }
> {code}
> But I find I query the SubmitTime and LaunchTime in hive and compare 
> JobHistory File time , I find that the submitTime  and launchTime was wrong.
> Finally,I change to use the FastDateFormat to parse the time format and the 
> time become right



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to