'How to call a method in other class/object in Scala using azure Data bricks Notebooks

I have below similar scenario in local Scala IDE. I was trying to replicate same in Azure Databricks Notebook. I was not able to do it.

Scenario Explained: I have one main class. I am calling methods in other object in to main class using Threading to execute parallelly.

I have tried by putting each object in different notebook and tried in data bricks. But able to do.

Main Class

object cli_main {
    
   def main(args: Array[String]): Unit = {
    
    var ModuleOneStart = "Y"
    var ModuleTwoStart = "Y"
    
    var ResultOne="0"
    var ResultTwo="0"
    
    var a=100
    var b=200
        
    val ThreadOne = new Thread {
        override def run(): Unit = {
            ResultOne = cli_cpm.cpm_process(a, b)
          }
        }
    val ThreadTwo = new Thread {
         override def run(): Unit = {
             ResultTwo = cli_res.res_process(a, b)
            }
        }
                
    if (ModuleOneStart == "Y") { 
          ThreadOne.start()
        }
    if (ModuleTwoStart == "Y") {
            ThreadTwo.start()
        }
    
    }
    
}

Method-1

object cli_cpm extends Thread {
    def cpm_process(a: Int, b: Int): String = {
    
    val mul=a*b
    
    if(mul>100){
    "1"  //return
    }
    "0"//return
    }
}

Method-2

object cli_res extends Thread {
    def res_process(a: Int, b: Int): String = {
    
    val sum=a+b
    
    if(sum>10){
    "1"  //return
    }
    "0"//return
    }
}

I know %run and dbutils.notebook.run are used to call a notebook.

Any different way to implement above scenario in Azure Databricks.



Solution 1:[1]

You can run one notebook into another using two ways:

  1. %run

%run notebook1.ipynb

  1. Databricks Utilities ( dbutils )

dbutils.notebook.run()

Other than these two options you can run multiple notebooks at the same time by using standard Scala and Python constructs such as Threads (Scala, Python) and Futures (Scala, Python).

Follow databricks official documentation

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AbhishekKhandave-MT