Skip to main content

All Questions

0 votes
1 answer
44 views

Instantiate lazy val which depends on runtime parameter in concurrent env

I need to instantiate MyHttpClient as Singleton. MyHttpClient is used by multiple threads. Solution below works, but it's ugly and should have issue with endpoint, I just didn't hit it yet. endpoint ...
Capacytron's user avatar
  • 3,758
30 votes
2 answers
20k views

Difference when serializing a lazy val with or without @transient

Working on spark, sometimes I need to send a non-serializable object in each task. A common pattern is @transient lazy val, e.g class A(val a: Int) def compute(rdd: RDD[Int]) = { // lazy val ...
Hao Ren's user avatar
  • 986