How do I guarantee that I am using not the default/global implicit context

I have a scala file that has this import
import scala.concurrent.ExecutionContext.Implicits.global

This works fine as the Future I am using works fine in my methods in that file. However, I have created a separate method that will be used for disk IO and I have a new execution context. I want this method to use this context while other methods can continue to use the default context. How do I guarantee that? I currently do this as follows

private def testContext():Future[Int]  = {
   val system = ActorSystem.create()
   //implicit val executionContext1 = system.dispatchers.lookup("blocking-io-dispatcher")
   implicit val myexecutionContext = system.dispatchers.lookup("blocking-io-dispatcher.db-backup-context")
   Future{logger.error("inside my new thread pool wonderland");10}{myexecutionContext}

Is there a way without specifying the “myexecutionContext” like this at the end of each Future call, I can make this method still use “myexecutionContext” for all Future calls? In short, I do not want to be specifying “myexecutionContext” again and again as a parameter inside my “testContext” method. How do I do that?

If the file has the global execution context as an import and you can’t remove than then you can’t get there from here.

If you didn’t have the import than you could assign myexecutionContext to an implicit variable in textContext and you wouldn’t have to provide it explicitly. With the import trying to make your EC implicit will give an implicit conflict (i.e., two values of the same type are implicit so the compiler cannot figure out which you want). Explicitly providing as you have done is therefor the best option.

I’m not sure what the problem is. This seems to work fine:

import scala.concurrent.ExecutionContext.Implicits.global

object Test extends App {

  import scala.concurrent.{ ExecutionContext, Future }

  val exec = java.util.concurrent.Executors.newCachedThreadPool

  def testContext() = {
    implicit val localExecutionContext = ExecutionContext.fromExecutorService(exec)
    Future {
      Thread.currentThread().getName
    }
  }

  for (name <- testContext()) println(Thread.currentThread.getName + ", " + name)
  exec.shutdown()
}

This gives me the output:

scala-execution-context-global-11, pool-1-thread-1

In other words, the future is executed by the user-defined execution context while printing is still done by the default context, i.e., the local implicit is used within method testContext.