package main
"log"
"math/rand"
"time"
)
//利用随机函数模拟不同文件的处理时间
r := rand.New(rand.NewSource(time.Now().UnixNano()))
x := r.Intn(20)
log.Println("UploadNetvalueFile: ", x)
time.Sleep(time.Second * time.Duration(x))
log.Println("UploadNetvalueFile OK")
done <- true
}
//利用随机函数模拟不同文件的处理时间
r := rand.New(rand.NewSource(time.Now().UnixNano() + 10))
x := r.Intn(20)
log.Println("UplaodSaleFareFile: ", x)
time.Sleep(time.Second * time.Duration(x))
log.Println("UplaodSaleFareFile OK ")
done <- true
}
t1 := time.Now()
tasknum := 2
done := make(chan bool, tasknum)
time.Sleep(time.Second * 1)
log.Println("create netvalue file !")
go UploadNetvalueFile(done)
time.Sleep(time.Second * 1)
log.Println("create salefare file !")
go UplaodSaleFareFile(done)
func() {
for i := 0; i < tasknum; i++ {
log.Println(<-done)
}
}()
log.Printf("耗时:%d\n", t2.Sub(t1))
}