Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why setConfiguration(Configuration conf) method of UserGroupInformation class is static?

Tags:

java

hadoop

hdfs

Why UserGroupInformation class is designed this way? Why setConfiguration(Configuration conf) method of UserGroupInformation class is static ?

My understanding is that this will restrict client to be able to connect to only 1 cluster per JVM.

How can we connect to multiple clusters at the same time from single JVM? I think this is a very basic scenario currently not being supported by Hadoop API.

Any help would be appreciated.

like image 663
user1522820 Avatar asked Apr 25 '16 16:04

user1522820


1 Answers

What is static method?

In general, main motivation for making a method static is convenience. You can call a static method without creating any object, just by using it's class name.So if you need a method, which you want to call directly by class name, make that method static. Utility classes e.g. java.lang.Math or StringUtils, are good examples of classes, which uses static methods.

What static method does?

  1. Static method doesn't modify state of object. Since state of object is maintained as instance variables
  2. Static method mostly operates on arguments, almost all static method accepts arguments, perform some calculation and return value.

What setConfiguration does?

setConfiguration(Configuration conf) -

Set the static configuration for UGI. In particular, set the security authentication mechanism and the group look up service.

How can we connect to multiple clusters at the same time from single JVM? I think this is a very basic scenario currently not being supported by Hadoop API.

Ans: Hadoop API is using like singleton design pattern here. You cannot do that because if you can imagine ever requiring to use object inheritance or needing to use polymorphism for your method, you should definitely skip the static and make it an instance method.

A good scenerio is described here: Static methods are a code smell

Resource Link:

  1. When to make a method static in Java
  2. Java Singleton Design Pattern Best Practices with Examples
like image 138
SkyWalker Avatar answered Sep 19 '22 06:09

SkyWalker