function initcommon(logFcn)
; %#ok Undocumented
% Copyright 2009-2017 The MathWorks, Inc.
        
% Initialization common to workers and clients

% Log errors to fprintf if no other mechanism is supplied.
if nargin < 1
    logFcn = @fprintf;
end

dctErrorIfNoJVM();

% Set JVM properties for RMI and DNS
RMI_connectionTimeoutMillis = '10000';
RMI_readTimeoutMillis = '300000';
DNS_lookupIntervalSecs = '300';
try
    java.lang.System.setProperty('sun.rmi.transport.connectionTimeout', RMI_connectionTimeoutMillis);
catch err
    % It's OK if we can't set the custom value for the timeout - we'll just use 
    % the default value of 15000ms.
    logFcn('Failed to set RMI Connection Timeout.  Reason: %s', err.getReport());
end
try
    java.lang.System.setProperty('sun.rmi.transport.tcp.readTimeout', RMI_readTimeoutMillis);
catch err
    % It's OK if we can't set the custom value for the timeout - we'll just use 
    % the default value of 2 hours
    logFcn('Failed to set RMI Read Timeout.  Reason: %s', err.getReport());
end
try
    java.lang.System.setProperty('sun.net.inetaddr.ttl', DNS_lookupIntervalSecs);
catch err
    % It's OK if we can't set the custom value for the ttl - we'll just use 
    % the default value of -1, which means "cache forever"
    logFcn('Failed to set DNS Lookup Interval Timeout.  Reason: %s', err.getReport());
end

% Make sure we never try and load code from anywhere but local classpath
java.lang.System.setProperty('java.rmi.server.codebase', '');
java.lang.System.setProperty('java.rmi.server.useCodebaseOnly', 'true');

% Initialize MatlabRefStore
com.mathworks.toolbox.distcomp.util.MatlabRefStore.initMatlabRef;
